blob: 4a51fa86893ccf0bcc15845afe8745f80151f55e (
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#include "mutex.h"
#ifdef WIN32
#include <windows.h>
void mossrose_mutex_init(mossrose_mutex_t *mutex)
{
*mutex = CreateMutex(NULL, false, NULL);
}
void mossrose_mutex_lock(mossrose_mutex_t *mutex)
{
WaitForSingleObject(*mutex, INFINITE);
}
int mossrose_mutex_trylock(mossrose_mutex_t *mutex)
{
int result = WaitForSingleObject(*mutex, 0);
return result != WAIT_OBJECT_0;
}
void mossrose_mutex_unlock(mossrose_mutex_t *mutex)
{
ReleaseMutex(*mutex);
}
void mossrose_mutex_destroy(mossrose_mutex_t *mutex)
{
ReleaseMutex(*mutex);
}
#else
#include <pthread.h>
void mossrose_mutex_init(mossrose_mutex_t *mutex)
{
pthread_mutex_init(mutex, NULL);
}
void mossrose_mutex_lock(mossrose_mutex_t *mutex)
{
pthread_mutex_lock(mutex);
}
int mossrose_mutex_trylock(mossrose_mutex_t *mutex)
{
return pthread_mutex_trylock(mutex);
}
void mossrose_mutex_unlock(mossrose_mutex_t *mutex)
{
pthread_mutex_unlock(mutex);
}
void mossrose_mutex_destroy(mossrose_mutex_t *mutex)
{
pthread_mutex_destroy(mutex);
}
#endif
|