This source file includes following definitions.
- _sir_condcreate
- _sir_condsignal
- _sir_condbroadcast
- _sir_conddestroy
- _sir_condwait
- _sir_condwait_timeout
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 #include "sir/condition.h"
33 #include "sir/internal.h"
34 #include "sir/platform.h"
35
36 bool _sir_condcreate(sir_condition* cond) {
37 bool valid = _sir_validptr(cond);
38
39 if (valid) {
40 #if !defined(__WIN__)
41 int op = pthread_cond_init(cond, NULL);
42 valid = 0 == op ? true : _sir_handleerr(op);
43 #else
44 InitializeConditionVariable(cond);
45 #endif
46 }
47
48 return valid;
49 }
50
51 #if 0
52 bool _sir_condsignal(sir_condition* cond) {
53 bool valid = _sir_validptr(cond);
54
55 if (valid) {
56 # if !defined(__WIN__)
57 int op = pthread_cond_signal(cond);
58 valid = 0 == op ? true : _sir_handleerr(op);
59 # else
60 WakeConditionVariable(cond);
61 # endif
62 }
63
64 return valid;
65 }
66 #endif
67
68 bool _sir_condbroadcast(sir_condition* cond) {
69 bool valid = _sir_validptr(cond);
70
71 if (valid) {
72 #if !defined(__WIN__)
73 int op = pthread_cond_broadcast(cond);
74 valid = 0 == op ? true : _sir_handleerr(op);
75 #else
76 WakeAllConditionVariable(cond);
77 #endif
78 }
79
80 return valid;
81 }
82
83 bool _sir_conddestroy(sir_condition* cond) {
84 bool valid = _sir_validptr(cond);
85
86 if (valid) {
87 #if !defined(__WIN__)
88 int op = pthread_cond_destroy(cond);
89 valid = 0 == op ? true : _sir_handleerr(op);
90 #else
91 SIR_UNUSED(cond);
92 #endif
93 }
94
95 return valid;
96 }
97
98 #if 0
99 bool _sir_condwait(sir_condition* cond, sir_mutex* mutex) {
100 bool valid = _sir_validptr(cond) && _sir_validptr(mutex);
101
102 if (valid) {
103 # if !defined(__WIN__)
104 int op = pthread_cond_wait(cond, mutex);
105 valid = 0 == op ? true : _sir_handleerr(op);
106 # else
107 DWORD howlong = INFINITE;
108 valid = _sir_condwait_timeout(cond, mutex, &howlong);
109 # endif
110 }
111
112 return valid;
113 }
114 #endif
115
116 bool _sir_condwait_timeout(sir_condition* cond, sir_mutex* mutex,
117 const sir_wait* howlong) {
118 bool valid = _sir_validptr(cond) && _sir_validptr(mutex) && _sir_validptr(howlong);
119
120 if (valid) {
121 #if !defined(__WIN__)
122 int op = pthread_cond_timedwait(cond, mutex, howlong);
123 valid = 0 == op ? true : ETIMEDOUT == op ? false : _sir_handleerr(op);
124 #else
125 valid = (FALSE != SleepConditionVariableCS(cond, mutex, *howlong))
126 ? true : _sir_handlewin32err(GetLastError());
127 #endif
128 }
129
130 return valid;
131 }