Initial commit
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
#include "Internal.h"
|
||||
#include "Codemap.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
CgeMutex *CgeMutexNew(int *result) {
|
||||
CgeMutex *mutex;
|
||||
int code = CGE_THREAD_EOOM;
|
||||
|
||||
mutex = malloc(sizeof(*mutex));
|
||||
if (mutex && (code = errorToErrorCode(pthread_mutex_init(&mutex->handle, NULL)))) {
|
||||
free(mutex);
|
||||
mutex = NULL;
|
||||
}
|
||||
|
||||
if (result)
|
||||
*result = code;
|
||||
|
||||
return mutex;
|
||||
}
|
||||
|
||||
void CgeMutexFree(CgeMutex *mutex) {
|
||||
if (!mutex)
|
||||
return;
|
||||
|
||||
pthread_mutex_destroy(&mutex->handle);
|
||||
free(mutex);
|
||||
}
|
||||
|
||||
int CgeMutexLock(CgeMutex *mutex, int *result) {
|
||||
int code;
|
||||
|
||||
code = errorToErrorCode(pthread_mutex_lock(&mutex->handle));
|
||||
if (result)
|
||||
*result = code;
|
||||
|
||||
return code == CGE_THREAD_EOK;
|
||||
}
|
||||
|
||||
int CgeMutexUnlock(CgeMutex *mutex, int *result) {
|
||||
int code;
|
||||
|
||||
code = errorToErrorCode(pthread_mutex_unlock(&mutex->handle));
|
||||
if (result)
|
||||
*result = code;
|
||||
|
||||
return code == CGE_THREAD_EOK;
|
||||
}
|
||||
|
||||
int CgeMutexTryLock(CgeMutex *mutex, int *result) {
|
||||
int code;
|
||||
|
||||
code = errorToErrorCode(pthread_mutex_trylock(&mutex->handle));
|
||||
if (result)
|
||||
*result = code;
|
||||
|
||||
return code == CGE_THREAD_EOK;
|
||||
}
|
||||
Reference in New Issue
Block a user