Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(601)

Side by Side Diff: mojo/edk/system/wait_set_dispatcher.cc

Issue 2096683003: Add yet another threaded test of WaitSetDispatcher. (Closed) Base URL: https://github.com/domokit/mojo.git@work792_wait_set_5.2-x-work791_wait_set_5.1-x-work790_wait_set_5
Patch Set: improve test and fix bug Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojo/edk/system/wait_set_dispatcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/system/wait_set_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698