summaryrefslogtreecommitdiff
path: root/src/mutex.h
blob: 84d1f63776cd8c110a5e4b2583927606d0426103 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef MOSSROSE_MUTEX_H
#define MOSSROSE_MUTEX_H


#ifdef WIN32
#include <windows.h>
typedef HANDLE mossrose_mutex_t;
#else
#include <pthread.h>
typedef pthread_mutex_t mossrose_mutex_t;
#endif

/* initialize a mutex */
void mossrose_mutex_init(mossrose_mutex_t *mutex);

/* lock a mutex, hanging until locked */
void mossrose_mutex_lock(mossrose_mutex_t *mutex);

/* attempt to lock a mutex. returns 0 on success and 1 otherwise */
int mossrose_mutex_trylock(mossrose_mutex_t *mutex);

/* unlock a mutex */
void mossrose_mutex_unlock(mossrose_mutex_t *mutex);

/* destroy a mutex */
void mossrose_mutex_destroy(mossrose_mutex_t *mutex);

#endif