1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #ifndef SYSTHREAD_H
20 #define SYSTHREAD_H
21
22 #include <attribute.h>
23
24 #ifdef THREADS_ENABLED
25
26 #ifdef HAVE_PTHREAD
27
28 #include <pthread.h>
29
30
31
32 typedef pthread_mutex_t sys_mutex_t;
33
34 typedef pthread_cond_t sys_cond_t;
35
36
37 typedef pthread_t sys_thread_t;
38
39 #else
40
41 #ifdef WINDOWSNT
42
43
44
45
46
47
48
49 typedef struct {
50 struct _CRITICAL_SECTION_DEBUG *DebugInfo;
51 long LockCount;
52 long RecursionCount;
53 void *OwningThread;
54 void *LockSemaphore;
55 unsigned long SpinCount;
56 } w32thread_critsect;
57
58 enum { CONDV_SIGNAL = 0, CONDV_BROADCAST = 1, CONDV_MAX = 2 };
59
60 typedef struct {
61
62 unsigned wait_count;
63
64 w32thread_critsect wait_count_lock;
65
66 void *events[CONDV_MAX];
67 bool initialized;
68 } w32thread_cond_t;
69
70 typedef w32thread_critsect sys_mutex_t;
71
72 typedef w32thread_cond_t sys_cond_t;
73
74 typedef unsigned long sys_thread_t;
75
76 #else
77
78 #error port me
79
80 #endif
81 #endif
82
83 #else
84
85
86 typedef int sys_mutex_t;
87 typedef int sys_cond_t;
88 typedef int sys_thread_t;
89
90 #endif
91
92 typedef void *(thread_creation_function) (void *);
93
94 extern void sys_mutex_init (sys_mutex_t *);
95 extern void sys_mutex_lock (sys_mutex_t *);
96 extern void sys_mutex_unlock (sys_mutex_t *);
97
98 extern void sys_cond_init (sys_cond_t *);
99 extern void sys_cond_wait (sys_cond_t *, sys_mutex_t *);
100 extern void sys_cond_signal (sys_cond_t *);
101 extern void sys_cond_broadcast (sys_cond_t *);
102 extern void sys_cond_destroy (sys_cond_t *);
103
104 NODISCARD extern sys_thread_t sys_thread_self (void);
105 NODISCARD extern bool sys_thread_equal (sys_thread_t, sys_thread_t);
106
107 NODISCARD extern bool sys_thread_create (sys_thread_t *,
108 thread_creation_function *, void *);
109
110 extern void sys_thread_yield (void);
111 extern void sys_thread_set_name (const char *);
112
113 #endif