| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/waitable_event.h" | 5 #include "base/waitable_event.h" |
| 6 | 6 |
| 7 #include "base/condition_variable.h" | 7 #include "base/condition_variable.h" |
| 8 #include "base/lock.h" | 8 #include "base/lock.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 | 10 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 // If return value == 0: | 295 // If return value == 0: |
| 296 // The locks of the WaitableEvents have been taken in order and the Waiter has | 296 // The locks of the WaitableEvents have been taken in order and the Waiter has |
| 297 // been enqueued in the wait-list of each. None of the WaitableEvents are | 297 // been enqueued in the wait-list of each. None of the WaitableEvents are |
| 298 // currently signaled | 298 // currently signaled |
| 299 // else: | 299 // else: |
| 300 // None of the WaitableEvent locks are held. The Waiter has not been enqueued | 300 // None of the WaitableEvent locks are held. The Waiter has not been enqueued |
| 301 // in any of them and the return value is the index of the first WaitableEvent | 301 // in any of them and the return value is the index of the first WaitableEvent |
| 302 // which was signaled, from the end of the array. | 302 // which was signaled, from the end of the array. |
| 303 // ----------------------------------------------------------------------------- | 303 // ----------------------------------------------------------------------------- |
| 304 // static | 304 // static |
| 305 unsigned WaitableEvent::EnqueueMany | 305 size_t WaitableEvent::EnqueueMany |
| 306 (std::pair<WaitableEvent*, size_t>* waitables, | 306 (std::pair<WaitableEvent*, size_t>* waitables, |
| 307 unsigned count, Waiter* waiter) { | 307 size_t count, Waiter* waiter) { |
| 308 if (!count) | 308 if (!count) |
| 309 return 0; | 309 return 0; |
| 310 | 310 |
| 311 waitables[0].first->lock_.Acquire(); | 311 waitables[0].first->lock_.Acquire(); |
| 312 if (waitables[0].first->signaled_) { | 312 if (waitables[0].first->signaled_) { |
| 313 if (!waitables[0].first->manual_reset_) | 313 if (!waitables[0].first->manual_reset_) |
| 314 waitables[0].first->signaled_ = false; | 314 waitables[0].first->signaled_ = false; |
| 315 waitables[0].first->lock_.Release(); | 315 waitables[0].first->lock_.Release(); |
| 316 return count; | 316 return count; |
| 317 } | 317 } |
| 318 | 318 |
| 319 const unsigned r = EnqueueMany(waitables + 1, count - 1, waiter); | 319 const size_t r = EnqueueMany(waitables + 1, count - 1, waiter); |
| 320 if (r) { | 320 if (r) { |
| 321 waitables[0].first->lock_.Release(); | 321 waitables[0].first->lock_.Release(); |
| 322 } else { | 322 } else { |
| 323 waitables[0].first->Enqueue(waiter); | 323 waitables[0].first->Enqueue(waiter); |
| 324 } | 324 } |
| 325 | 325 |
| 326 return r; | 326 return r; |
| 327 } | 327 } |
| 328 | 328 |
| 329 // ----------------------------------------------------------------------------- | 329 // ----------------------------------------------------------------------------- |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 return true; | 383 return true; |
| 384 } | 384 } |
| 385 } | 385 } |
| 386 | 386 |
| 387 return false; | 387 return false; |
| 388 } | 388 } |
| 389 | 389 |
| 390 // ----------------------------------------------------------------------------- | 390 // ----------------------------------------------------------------------------- |
| 391 | 391 |
| 392 } // namespace base | 392 } // namespace base |
| OLD | NEW |