| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mojo/edk/system/wait_set_dispatcher.h" | 5 #include "mojo/edk/system/wait_set_dispatcher.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 void WaitSetDispatcher::CloseImplNoLock() { | 113 void WaitSetDispatcher::CloseImplNoLock() { |
| 114 mutex().AssertHeld(); | 114 mutex().AssertHeld(); |
| 115 | 115 |
| 116 CookieToEntryMap entries; | 116 CookieToEntryMap entries; |
| 117 std::swap(entries_, entries); | 117 std::swap(entries_, entries); |
| 118 triggered_head_ = nullptr; | 118 triggered_head_ = nullptr; |
| 119 triggered_tail_ = nullptr; | 119 triggered_tail_ = nullptr; |
| 120 triggered_count_ = 0u; | 120 triggered_count_ = 0u; |
| 121 | 121 |
| 122 cv_.Signal(); | 122 cv_.SignalAll(); |
| 123 | 123 |
| 124 // We want to remove the awakables outside the lock, so we have to unlock | 124 // We want to remove the awakables outside the lock, so we have to unlock |
| 125 // |mutex()|. Note that while unlocked, |Awake()| may get called. | 125 // |mutex()|. Note that while unlocked, |Awake()| may get called. |
| 126 // TODO(vtl): This is pretty terrible, but changing it would require pretty | 126 // TODO(vtl): This is pretty terrible, but changing it would require pretty |
| 127 // invasive changes in many other places. We really count on |Dispatcher| not | 127 // invasive changes in many other places. We really count on |Dispatcher| not |
| 128 // doing anything interesting after calling |CloseImplNoLock()|, and since | 128 // doing anything interesting after calling |CloseImplNoLock()|, and since |
| 129 // |CloseImplNoLock()| is allowed to do nothing all the lock invariants are | 129 // |CloseImplNoLock()| is allowed to do nothing all the lock invariants are |
| 130 // satisfied. | 130 // satisfied. |
| 131 DCHECK(is_closed_no_lock()); | 131 DCHECK(is_closed_no_lock()); |
| 132 mutex().Unlock(); | 132 mutex().Unlock(); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } | 418 } |
| 419 } | 419 } |
| 420 | 420 |
| 421 void WaitSetDispatcher::AddTriggeredNoLock(Entry* entry) { | 421 void WaitSetDispatcher::AddTriggeredNoLock(Entry* entry) { |
| 422 DCHECK(!entry->is_triggered); | 422 DCHECK(!entry->is_triggered); |
| 423 DCHECK(!entry->triggered_previous); | 423 DCHECK(!entry->triggered_previous); |
| 424 DCHECK(!entry->triggered_next); | 424 DCHECK(!entry->triggered_next); |
| 425 | 425 |
| 426 entry->is_triggered = true; | 426 entry->is_triggered = true; |
| 427 if (!triggered_count_) | 427 if (!triggered_count_) |
| 428 cv_.Signal(); | 428 cv_.SignalAll(); |
| 429 triggered_count_++; | 429 triggered_count_++; |
| 430 | 430 |
| 431 if (!triggered_tail_) { | 431 if (!triggered_tail_) { |
| 432 DCHECK(!triggered_head_); | 432 DCHECK(!triggered_head_); |
| 433 triggered_head_ = entry; | 433 triggered_head_ = entry; |
| 434 triggered_tail_ = entry; | 434 triggered_tail_ = entry; |
| 435 return; | 435 return; |
| 436 } | 436 } |
| 437 | 437 |
| 438 Entry* old_tail = triggered_tail_; | 438 Entry* old_tail = triggered_tail_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 460 } else { | 460 } else { |
| 461 entry->triggered_next->triggered_previous = entry->triggered_previous; | 461 entry->triggered_next->triggered_previous = entry->triggered_previous; |
| 462 } | 462 } |
| 463 | 463 |
| 464 entry->triggered_previous = nullptr; | 464 entry->triggered_previous = nullptr; |
| 465 entry->triggered_next = nullptr; | 465 entry->triggered_next = nullptr; |
| 466 } | 466 } |
| 467 | 467 |
| 468 } // namespace system | 468 } // namespace system |
| 469 } // namespace mojo | 469 } // namespace mojo |
| OLD | NEW |