line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
// Copyright (c) 2023 Yuki Kimoto |
2
|
|
|
|
|
|
|
// MIT License |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#include "spvm_mutex.h" |
5
|
|
|
|
|
|
|
#include "spvm_allocator.h" |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#if defined(_WIN32) |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#include |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
void SPVM_MUTEX_init(void* mutex) { |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
InitializeSRWLock((SRWLOCK*)mutex); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
void SPVM_MUTEX_destroy(void* mutex) { |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
void SPVM_MUTEX_lock (void* mutex) { |
21
|
|
|
|
|
|
|
AcquireSRWLockExclusive((SRWLOCK*)mutex); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
void SPVM_MUTEX_unlock (void* mutex) { |
25
|
|
|
|
|
|
|
ReleaseSRWLockExclusive((SRWLOCK*)mutex); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
void SPVM_MUTEX_reader_lock (void* mutex) { |
29
|
|
|
|
|
|
|
AcquireSRWLockShared((SRWLOCK*)mutex); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
void SPVM_MUTEX_reader_unlock (void* mutex) { |
33
|
|
|
|
|
|
|
ReleaseSRWLockShared((SRWLOCK*)mutex); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
int32_t SPVM_MUTEX_size () { |
37
|
|
|
|
|
|
|
return sizeof(SRWLOCK); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#else |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#include |
43
|
|
|
|
|
|
|
#include |
44
|
|
|
|
|
|
|
#include |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#define SAFE_PTHREAD(fncall) \ |
47
|
|
|
|
|
|
|
do { \ |
48
|
|
|
|
|
|
|
if ((fncall) != 0) abort(); \ |
49
|
|
|
|
|
|
|
} while (0) |
50
|
|
|
|
|
|
|
|
51
|
523031
|
|
|
|
|
|
void SPVM_MUTEX_init(void* mutex) { |
52
|
|
|
|
|
|
|
|
53
|
523031
|
50
|
|
|
|
|
SAFE_PTHREAD(pthread_rwlock_init((pthread_rwlock_t*)mutex, NULL)); |
54
|
523031
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
520166
|
|
|
|
|
|
void SPVM_MUTEX_destroy(void* mutex) { |
57
|
520166
|
50
|
|
|
|
|
SAFE_PTHREAD(pthread_rwlock_destroy((pthread_rwlock_t*)mutex)); |
58
|
520166
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
10869212
|
|
|
|
|
|
void SPVM_MUTEX_lock (void* mutex) { |
61
|
10869212
|
50
|
|
|
|
|
SAFE_PTHREAD(pthread_rwlock_wrlock((pthread_rwlock_t*)mutex)); |
62
|
10869212
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
10869212
|
|
|
|
|
|
void SPVM_MUTEX_unlock (void* mutex) { |
65
|
10869212
|
50
|
|
|
|
|
SAFE_PTHREAD(pthread_rwlock_unlock((pthread_rwlock_t*)mutex)); |
66
|
10869212
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
312355
|
|
|
|
|
|
void SPVM_MUTEX_reader_lock (void* mutex) { |
69
|
312355
|
50
|
|
|
|
|
SAFE_PTHREAD(pthread_rwlock_rdlock((pthread_rwlock_t*)mutex)); |
70
|
312355
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
312355
|
|
|
|
|
|
void SPVM_MUTEX_reader_unlock (void* mutex) { |
73
|
312355
|
50
|
|
|
|
|
SAFE_PTHREAD(pthread_rwlock_unlock((pthread_rwlock_t*)mutex)); |
74
|
312355
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
5670346
|
|
|
|
|
|
int32_t SPVM_MUTEX_size () { |
77
|
5670346
|
|
|
|
|
|
return sizeof(pthread_rwlock_t); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#endif |