blob: 15af8bd22869aa319462ca118233d2184ac853b2 (
plain) (
blame)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*
* Mr. 4th Dimention - Allen Webster
*
* 18.07.2017
*
* Linux threading wrapper
*
*/
// TOP
#error IS THIS STILL REAL? (February 27th 2020)
#if !defined(MAC_THREADING_WRAPPER)
#define MAC_THREADING_WRAPPER
#define PLAT_THREAD_SIG(n) void* n(void *ptr)
typedef PLAT_THREAD_SIG(Thread_Function);
union Thread{
pthread_t t;
FixSize(THREAD_TYPE_SIZE);
};
union Mutex{
pthread_mutex_t crit;
FixSize(MUTEX_TYPE_SIZE);
};
union Condition_Variable{
pthread_cond_t cv;
FixSize(CONDITION_VARIABLE_TYPE_SIZE);
};
internal void
system_init_and_launch_thread(Thread *t, Thread_Function *proc, void *ptr){
pthread_create(&t->t, 0, proc, ptr);
}
internal void
system_init_lock(Mutex *m){
pthread_mutex_init(&m->crit, NULL);
}
internal void
system_acquire_lock(Mutex *m){
pthread_mutex_lock(&m->crit);
}
internal void
system_release_lock(Mutex *m){
pthread_mutex_unlock(&m->crit);
}
internal void
system_init_cv(Condition_Variable *cv){
pthread_cond_init(&cv->cv, NULL);
}
internal void
system_wait_cv(Condition_Variable *cv, Mutex *m){
pthread_cond_wait(&cv->cv, &m->crit);
}
internal void
system_signal_cv(Condition_Variable *cv, Mutex *m){
pthread_cond_signal(&cv->cv);
}
#endif
// BOTTOM
|