OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "platform/thread.h" | 8 #include "platform/thread.h" |
9 | 9 |
10 #include <process.h> // NOLINT | 10 #include <process.h> // NOLINT |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 FATAL1("Mutex try lock failed %d", GetLastError()); | 133 FATAL1("Mutex try lock failed %d", GetLastError()); |
134 } | 134 } |
135 ASSERT(result == WAIT_TIMEOUT); | 135 ASSERT(result == WAIT_TIMEOUT); |
136 return false; | 136 return false; |
137 } | 137 } |
138 | 138 |
139 | 139 |
140 void Mutex::Unlock() { | 140 void Mutex::Unlock() { |
141 BOOL result = ReleaseSemaphore(data_.semaphore_, 1, NULL); | 141 BOOL result = ReleaseSemaphore(data_.semaphore_, 1, NULL); |
142 if (result == 0) { | 142 if (result == 0) { |
143 FATAL1("Mutex unlock failed", GetLastError()); | 143 FATAL1("Mutex unlock failed %d", GetLastError()); |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 | 147 |
148 ThreadLocalKey MonitorWaitData::monitor_wait_data_key_ = | 148 ThreadLocalKey MonitorWaitData::monitor_wait_data_key_ = |
149 Thread::kUnsetThreadLocalKey; | 149 Thread::kUnsetThreadLocalKey; |
150 | 150 |
151 | 151 |
152 Monitor::Monitor() { | 152 Monitor::Monitor() { |
153 InitializeCriticalSection(&data_.cs_); | 153 InitializeCriticalSection(&data_.cs_); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 if (first != NULL) { | 237 if (first != NULL) { |
238 // Remove from list. | 238 // Remove from list. |
239 if (waiters_head_ == waiters_tail_) { | 239 if (waiters_head_ == waiters_tail_) { |
240 waiters_tail_ = waiters_head_ = NULL; | 240 waiters_tail_ = waiters_head_ = NULL; |
241 } else { | 241 } else { |
242 waiters_head_ = waiters_head_->next_; | 242 waiters_head_ = waiters_head_->next_; |
243 } | 243 } |
244 // Signal event. | 244 // Signal event. |
245 BOOL result = SetEvent(first->event_); | 245 BOOL result = SetEvent(first->event_); |
246 if (result == 0) { | 246 if (result == 0) { |
247 FATAL1("Monitor::Notify failed to signal event", GetLastError()); | 247 FATAL1("Monitor::Notify failed to signal event %d", GetLastError()); |
248 } | 248 } |
249 } | 249 } |
250 LeaveCriticalSection(&waiters_cs_); | 250 LeaveCriticalSection(&waiters_cs_); |
251 } | 251 } |
252 | 252 |
253 | 253 |
254 void MonitorData::SignalAndRemoveAllWaiters() { | 254 void MonitorData::SignalAndRemoveAllWaiters() { |
255 EnterCriticalSection(&waiters_cs_); | 255 EnterCriticalSection(&waiters_cs_); |
256 // Extract list to signal. | 256 // Extract list to signal. |
257 MonitorWaitData* current = waiters_head_; | 257 MonitorWaitData* current = waiters_head_; |
258 // Clear list. | 258 // Clear list. |
259 waiters_head_ = waiters_tail_ = NULL; | 259 waiters_head_ = waiters_tail_ = NULL; |
260 // Iterate and signal all events. | 260 // Iterate and signal all events. |
261 while (current != NULL) { | 261 while (current != NULL) { |
262 BOOL result = SetEvent(current->event_); | 262 BOOL result = SetEvent(current->event_); |
263 if (result == 0) { | 263 if (result == 0) { |
264 FATAL1("Failed to set event for NotifyAll", GetLastError()); | 264 FATAL1("Failed to set event for NotifyAll %d", GetLastError()); |
265 } | 265 } |
266 current = current->next_; | 266 current = current->next_; |
267 } | 267 } |
268 LeaveCriticalSection(&waiters_cs_); | 268 LeaveCriticalSection(&waiters_cs_); |
269 } | 269 } |
270 | 270 |
271 | 271 |
272 MonitorWaitData* MonitorData::GetMonitorWaitDataForThread() { | 272 MonitorWaitData* MonitorData::GetMonitorWaitDataForThread() { |
273 // Ensure that the thread local key for monitor wait data objects is | 273 // Ensure that the thread local key for monitor wait data objects is |
274 // initialized. | 274 // initialized. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 308 |
309 // Leave the monitor critical section while waiting. | 309 // Leave the monitor critical section while waiting. |
310 LeaveCriticalSection(&data_.cs_); | 310 LeaveCriticalSection(&data_.cs_); |
311 | 311 |
312 // Perform the actual wait on the event. | 312 // Perform the actual wait on the event. |
313 DWORD result = WAIT_FAILED; | 313 DWORD result = WAIT_FAILED; |
314 if (millis == 0) { | 314 if (millis == 0) { |
315 // Wait forever for a Notify or a NotifyAll event. | 315 // Wait forever for a Notify or a NotifyAll event. |
316 result = WaitForSingleObject(wait_data->event_, INFINITE); | 316 result = WaitForSingleObject(wait_data->event_, INFINITE); |
317 if (result == WAIT_FAILED) { | 317 if (result == WAIT_FAILED) { |
318 FATAL1("Monitor::Wait failed", GetLastError()); | 318 FATAL1("Monitor::Wait failed %d", GetLastError()); |
319 } | 319 } |
320 } else { | 320 } else { |
321 // Wait for the given period of time for a Notify or a NotifyAll | 321 // Wait for the given period of time for a Notify or a NotifyAll |
322 // event. | 322 // event. |
323 result = WaitForSingleObject(wait_data->event_, millis); | 323 result = WaitForSingleObject(wait_data->event_, millis); |
324 if (result == WAIT_FAILED) { | 324 if (result == WAIT_FAILED) { |
325 FATAL1("Monitor::Wait with timeout failed", GetLastError()); | 325 FATAL1("Monitor::Wait with timeout failed %d", GetLastError()); |
326 } | 326 } |
327 if (result == WAIT_TIMEOUT) { | 327 if (result == WAIT_TIMEOUT) { |
328 // No longer waiting. Remove from the list of waiters. | 328 // No longer waiting. Remove from the list of waiters. |
329 data_.RemoveWaiter(wait_data); | 329 data_.RemoveWaiter(wait_data); |
330 retval = kTimedOut; | 330 retval = kTimedOut; |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 // Reacquire the monitor critical section before continuing. | 334 // Reacquire the monitor critical section before continuing. |
335 EnterCriticalSection(&data_.cs_); | 335 EnterCriticalSection(&data_.cs_); |
(...skipping 12 matching lines...) Expand all Loading... |
348 // timeout before we signal it, that object will get an extra | 348 // timeout before we signal it, that object will get an extra |
349 // signal. This will be treated as a spurious wake-up and is OK | 349 // signal. This will be treated as a spurious wake-up and is OK |
350 // since all uses of monitors should recheck the condition after a | 350 // since all uses of monitors should recheck the condition after a |
351 // Wait. | 351 // Wait. |
352 data_.SignalAndRemoveAllWaiters(); | 352 data_.SignalAndRemoveAllWaiters(); |
353 } | 353 } |
354 | 354 |
355 } // namespace dart | 355 } // namespace dart |
356 | 356 |
357 #endif // defined(TARGET_OS_WINDOWS) | 357 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |