OLD | NEW |
1 /* | 1 /* |
2 Source: | 2 Source: |
3 http://www1.cse.wustl.edu/~schmidt/ACE-copying.html | 3 http://www1.cse.wustl.edu/~schmidt/ACE-copying.html |
4 | 4 |
5 License: | 5 License: |
6 Copyright and Licensing Information for ACE(TM), TAO(TM), CIAO(TM), DAnCE(TM), | 6 Copyright and Licensing Information for ACE(TM), TAO(TM), CIAO(TM), DAnCE(TM), |
7 and CoSMIC(TM) | 7 and CoSMIC(TM) |
8 | 8 |
9 ACE(TM), TAO(TM), CIAO(TM), DAnCE>(TM), and CoSMIC(TM) (henceforth referred to | 9 ACE(TM), TAO(TM), CIAO(TM), DAnCE>(TM), and CoSMIC(TM) (henceforth referred to |
10 as "DOC software") are copyrighted by Douglas C. Schmidt and his research | 10 as "DOC software") are copyrighted by Douglas C. Schmidt and his research |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 * http://www.cs.wustl.edu/~schmidt/win32-cv-1.html (section 3.2). | 77 * http://www.cs.wustl.edu/~schmidt/win32-cv-1.html (section 3.2). |
78 * Modifications: | 78 * Modifications: |
79 * 1) Dynamic detection of native support for condition variables. | 79 * 1) Dynamic detection of native support for condition variables. |
80 * 2) Use of WebRTC defined types and classes. Renaming of some functions. | 80 * 2) Use of WebRTC defined types and classes. Renaming of some functions. |
81 * 3) Introduction of a second event for wake all functionality. This prevents | 81 * 3) Introduction of a second event for wake all functionality. This prevents |
82 * a thread from spinning on the same condition variable, preventing other | 82 * a thread from spinning on the same condition variable, preventing other |
83 * threads from waking up. | 83 * threads from waking up. |
84 */ | 84 */ |
85 | 85 |
86 #include "webrtc/system_wrappers/source/condition_variable_event_win.h" | 86 #include "webrtc/system_wrappers/source/condition_variable_event_win.h" |
87 #include "webrtc/system_wrappers/source/critical_section_win.h" | 87 |
| 88 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
88 | 89 |
89 namespace webrtc { | 90 namespace webrtc { |
90 | 91 |
91 ConditionVariableEventWin::ConditionVariableEventWin() : eventID_(WAKEALL_0) { | 92 ConditionVariableEventWin::ConditionVariableEventWin() : eventID_(WAKEALL_0) { |
92 memset(&num_waiters_[0], 0, sizeof(num_waiters_)); | 93 memset(&num_waiters_[0], 0, sizeof(num_waiters_)); |
93 | 94 |
94 InitializeCriticalSection(&num_waiters_crit_sect_); | 95 InitializeCriticalSection(&num_waiters_crit_sect_); |
95 | 96 |
96 events_[WAKEALL_0] = CreateEvent(NULL, // no security attributes | 97 events_[WAKEALL_0] = CreateEvent(NULL, // no security attributes |
97 TRUE, // manual-reset, sticky event | 98 TRUE, // manual-reset, sticky event |
(...skipping 28 matching lines...) Expand all Loading... |
126 EnterCriticalSection(&num_waiters_crit_sect_); | 127 EnterCriticalSection(&num_waiters_crit_sect_); |
127 | 128 |
128 // Get the eventID for the event that will be triggered by next | 129 // Get the eventID for the event that will be triggered by next |
129 // WakeAll() call and start waiting for it. | 130 // WakeAll() call and start waiting for it. |
130 const EventWakeUpType eventID = | 131 const EventWakeUpType eventID = |
131 (WAKEALL_0 == eventID_) ? WAKEALL_1 : WAKEALL_0; | 132 (WAKEALL_0 == eventID_) ? WAKEALL_1 : WAKEALL_0; |
132 | 133 |
133 ++(num_waiters_[eventID]); | 134 ++(num_waiters_[eventID]); |
134 LeaveCriticalSection(&num_waiters_crit_sect_); | 135 LeaveCriticalSection(&num_waiters_crit_sect_); |
135 | 136 |
136 CriticalSectionWindows* cs = | 137 LeaveCriticalSection(&crit_sect.crit_); |
137 static_cast<CriticalSectionWindows*>(&crit_sect); | |
138 LeaveCriticalSection(&cs->crit); | |
139 HANDLE events[2]; | 138 HANDLE events[2]; |
140 events[0] = events_[WAKE]; | 139 events[0] = events_[WAKE]; |
141 events[1] = events_[eventID]; | 140 events[1] = events_[eventID]; |
142 const DWORD result = WaitForMultipleObjects(2, // Wait on 2 events. | 141 const DWORD result = WaitForMultipleObjects(2, // Wait on 2 events. |
143 events, | 142 events, |
144 FALSE, // Wait for either. | 143 FALSE, // Wait for either. |
145 max_time_in_ms); | 144 max_time_in_ms); |
146 | 145 |
147 const bool ret_val = (result != WAIT_TIMEOUT); | 146 const bool ret_val = (result != WAIT_TIMEOUT); |
148 | 147 |
149 EnterCriticalSection(&num_waiters_crit_sect_); | 148 EnterCriticalSection(&num_waiters_crit_sect_); |
150 --(num_waiters_[eventID]); | 149 --(num_waiters_[eventID]); |
151 | 150 |
152 // Last waiter should only be true for WakeAll(). WakeAll() correspond | 151 // Last waiter should only be true for WakeAll(). WakeAll() correspond |
153 // to position 1 in events[] -> (result == WAIT_OBJECT_0 + 1) | 152 // to position 1 in events[] -> (result == WAIT_OBJECT_0 + 1) |
154 const bool last_waiter = (result == WAIT_OBJECT_0 + 1) && | 153 const bool last_waiter = (result == WAIT_OBJECT_0 + 1) && |
155 (num_waiters_[eventID] == 0); | 154 (num_waiters_[eventID] == 0); |
156 LeaveCriticalSection(&num_waiters_crit_sect_); | 155 LeaveCriticalSection(&num_waiters_crit_sect_); |
157 | 156 |
158 if (last_waiter) { | 157 if (last_waiter) { |
159 // Reset/unset the WakeAll() event since all threads have been | 158 // Reset/unset the WakeAll() event since all threads have been |
160 // released. | 159 // released. |
161 ResetEvent(events_[eventID]); | 160 ResetEvent(events_[eventID]); |
162 } | 161 } |
163 | 162 |
164 EnterCriticalSection(&cs->crit); | 163 EnterCriticalSection(&crit_sect.crit_); |
165 return ret_val; | 164 return ret_val; |
166 } | 165 } |
167 | 166 |
168 void ConditionVariableEventWin::Wake() { | 167 void ConditionVariableEventWin::Wake() { |
169 EnterCriticalSection(&num_waiters_crit_sect_); | 168 EnterCriticalSection(&num_waiters_crit_sect_); |
170 const bool have_waiters = (num_waiters_[WAKEALL_0] > 0) || | 169 const bool have_waiters = (num_waiters_[WAKEALL_0] > 0) || |
171 (num_waiters_[WAKEALL_1] > 0); | 170 (num_waiters_[WAKEALL_1] > 0); |
172 LeaveCriticalSection(&num_waiters_crit_sect_); | 171 LeaveCriticalSection(&num_waiters_crit_sect_); |
173 | 172 |
174 if (have_waiters) { | 173 if (have_waiters) { |
(...skipping 11 matching lines...) Expand all Loading... |
186 const EventWakeUpType eventID = eventID_; | 185 const EventWakeUpType eventID = eventID_; |
187 const bool have_waiters = num_waiters_[eventID] > 0; | 186 const bool have_waiters = num_waiters_[eventID] > 0; |
188 LeaveCriticalSection(&num_waiters_crit_sect_); | 187 LeaveCriticalSection(&num_waiters_crit_sect_); |
189 | 188 |
190 if (have_waiters) { | 189 if (have_waiters) { |
191 SetEvent(events_[eventID]); | 190 SetEvent(events_[eventID]); |
192 } | 191 } |
193 } | 192 } |
194 | 193 |
195 } // namespace webrtc | 194 } // namespace webrtc |
OLD | NEW |