44 lines
1.1 KiB
C
44 lines
1.1 KiB
C
#ifndef INCLUDED_C_MUTEX_H
|
|||
|
|
#define INCLUDED_C_MUTEX_H
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_BASE_H
|
||
|
|
#include <c_Base.h>
|
||
|
|
#endif /*INCLUDED_C_BASE_H*/
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
#if defined(_WIN32) || defined(_WIN64)
|
||
|
|
#define PLATFORM_WINDOWS 1
|
||
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
||
|
|
#define WIN32_LEAN_AND_MEAN
|
||
|
|
#endif
|
||
|
|
#include <windows.h>
|
||
|
|
#else
|
||
|
|
#define PLATFORM_POSIX 1
|
||
|
|
#include <pthread.h>
|
||
|
|
#endif
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
#if defined(PLATFORM_WINDOWS)
|
||
|
|
CRITICAL_SECTION handle;
|
||
|
|
#elif defined(PLATFORM_POSIX)
|
||
|
|
pthread_mutex_t handle;
|
||
|
|
#endif
|
||
|
|
c_bool_t is_initialized;
|
||
|
|
} c_Mutex_t;
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
c_err_t c_Mutex_Init(c_Mutex_t* mutex);
|
||
|
|
void c_Mutex_Destroy(c_Mutex_t* mutex);
|
||
|
|
void c_Mutex_Lock(c_Mutex_t* mutex);
|
||
|
|
c_bool_t c_Mutex_TryLock(c_Mutex_t* mutex);
|
||
|
|
void c_Mutex_UnLock(c_Mutex_t* mutex);
|
||
|
|
|
||
|
|
#endif /*INCLUDED_C_MUTEX_H*/
|