This source file includes following definitions.
- _sir_condcreate
- _sir_condbroadcast
- _sir_conddestroy
- _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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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 }