| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 111 } |
| 112 | 112 |
| 113 ConditionVariableEventWin::~ConditionVariableEventWin() { | 113 ConditionVariableEventWin::~ConditionVariableEventWin() { |
| 114 CloseHandle(events_[WAKE]); | 114 CloseHandle(events_[WAKE]); |
| 115 CloseHandle(events_[WAKEALL_1]); | 115 CloseHandle(events_[WAKEALL_1]); |
| 116 CloseHandle(events_[WAKEALL_0]); | 116 CloseHandle(events_[WAKEALL_0]); |
| 117 | 117 |
| 118 DeleteCriticalSection(&num_waiters_crit_sect_); | 118 DeleteCriticalSection(&num_waiters_crit_sect_); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void ConditionVariableEventWin::SleepCS(CriticalSectionWrapper& crit_sect) { | 121 void ConditionVariableEventWin::SleepCS(CRITICAL_SECTION* crit_sect) { |
| 122 SleepCS(crit_sect, INFINITE); | 122 SleepCS(crit_sect, INFINITE); |
| 123 } | 123 } |
| 124 | 124 |
| 125 bool ConditionVariableEventWin::SleepCS(CriticalSectionWrapper& crit_sect, | 125 bool ConditionVariableEventWin::SleepCS(CRITICAL_SECTION* crit_sect, |
| 126 unsigned long max_time_in_ms) { | 126 unsigned long max_time_in_ms) { |
| 127 EnterCriticalSection(&num_waiters_crit_sect_); | 127 EnterCriticalSection(&num_waiters_crit_sect_); |
| 128 | 128 |
| 129 // 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 |
| 130 // WakeAll() call and start waiting for it. | 130 // WakeAll() call and start waiting for it. |
| 131 const EventWakeUpType eventID = | 131 const EventWakeUpType eventID = |
| 132 (WAKEALL_0 == eventID_) ? WAKEALL_1 : WAKEALL_0; | 132 (WAKEALL_0 == eventID_) ? WAKEALL_1 : WAKEALL_0; |
| 133 | 133 |
| 134 ++(num_waiters_[eventID]); | 134 ++(num_waiters_[eventID]); |
| 135 LeaveCriticalSection(&num_waiters_crit_sect_); | 135 LeaveCriticalSection(&num_waiters_crit_sect_); |
| 136 | 136 |
| 137 LeaveCriticalSection(&crit_sect.crit_); | 137 LeaveCriticalSection(crit_sect); |
| 138 HANDLE events[2]; | 138 HANDLE events[2]; |
| 139 events[0] = events_[WAKE]; | 139 events[0] = events_[WAKE]; |
| 140 events[1] = events_[eventID]; | 140 events[1] = events_[eventID]; |
| 141 const DWORD result = WaitForMultipleObjects(2, // Wait on 2 events. | 141 const DWORD result = WaitForMultipleObjects(2, // Wait on 2 events. |
| 142 events, | 142 events, |
| 143 FALSE, // Wait for either. | 143 FALSE, // Wait for either. |
| 144 max_time_in_ms); | 144 max_time_in_ms); |
| 145 | 145 |
| 146 const bool ret_val = (result != WAIT_TIMEOUT); | 146 const bool ret_val = (result != WAIT_TIMEOUT); |
| 147 | 147 |
| 148 EnterCriticalSection(&num_waiters_crit_sect_); | 148 EnterCriticalSection(&num_waiters_crit_sect_); |
| 149 --(num_waiters_[eventID]); | 149 --(num_waiters_[eventID]); |
| 150 | 150 |
| 151 // Last waiter should only be true for WakeAll(). WakeAll() correspond | 151 // Last waiter should only be true for WakeAll(). WakeAll() correspond |
| 152 // to position 1 in events[] -> (result == WAIT_OBJECT_0 + 1) | 152 // to position 1 in events[] -> (result == WAIT_OBJECT_0 + 1) |
| 153 const bool last_waiter = (result == WAIT_OBJECT_0 + 1) && | 153 const bool last_waiter = (result == WAIT_OBJECT_0 + 1) && |
| 154 (num_waiters_[eventID] == 0); | 154 (num_waiters_[eventID] == 0); |
| 155 LeaveCriticalSection(&num_waiters_crit_sect_); | 155 LeaveCriticalSection(&num_waiters_crit_sect_); |
| 156 | 156 |
| 157 if (last_waiter) { | 157 if (last_waiter) { |
| 158 // Reset/unset the WakeAll() event since all threads have been | 158 // Reset/unset the WakeAll() event since all threads have been |
| 159 // released. | 159 // released. |
| 160 ResetEvent(events_[eventID]); | 160 ResetEvent(events_[eventID]); |
| 161 } | 161 } |
| 162 | 162 |
| 163 EnterCriticalSection(&crit_sect.crit_); | 163 EnterCriticalSection(crit_sect); |
| 164 return ret_val; | 164 return ret_val; |
| 165 } | 165 } |
| 166 | 166 |
| 167 void ConditionVariableEventWin::Wake() { | 167 void ConditionVariableEventWin::Wake() { |
| 168 EnterCriticalSection(&num_waiters_crit_sect_); | 168 EnterCriticalSection(&num_waiters_crit_sect_); |
| 169 const bool have_waiters = (num_waiters_[WAKEALL_0] > 0) || | 169 const bool have_waiters = (num_waiters_[WAKEALL_0] > 0) || |
| 170 (num_waiters_[WAKEALL_1] > 0); | 170 (num_waiters_[WAKEALL_1] > 0); |
| 171 LeaveCriticalSection(&num_waiters_crit_sect_); | 171 LeaveCriticalSection(&num_waiters_crit_sect_); |
| 172 | 172 |
| 173 if (have_waiters) { | 173 if (have_waiters) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 185 const EventWakeUpType eventID = eventID_; | 185 const EventWakeUpType eventID = eventID_; |
| 186 const bool have_waiters = num_waiters_[eventID] > 0; | 186 const bool have_waiters = num_waiters_[eventID] > 0; |
| 187 LeaveCriticalSection(&num_waiters_crit_sect_); | 187 LeaveCriticalSection(&num_waiters_crit_sect_); |
| 188 | 188 |
| 189 if (have_waiters) { | 189 if (have_waiters) { |
| 190 SetEvent(events_[eventID]); | 190 SetEvent(events_[eventID]); |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 | 193 |
| 194 } // namespace webrtc | 194 } // namespace webrtc |
| OLD | NEW |