Files
cKit/Foundation/c_Mutex.h
T
2026-08-30 02:51:25 +08:00

45 lines
1.2 KiB
C

#ifndef INCLUDED_C_MUTEX_H
#define INCLUDED_C_MUTEX_H
#ifndef INCLUDED_C_TYPES_H
#include <c_Types.h>
#endif /*INCLUDED_C_TYPES_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*/