Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 * Use of this source code is governed by a BSD-style license that can be | |
| 3 * found in the LICENSE file. | |
| 4 */ | |
|
Sam Clegg
2013/07/17 17:34:56
C++ comments.
noelallen1
2013/07/17 21:00:18
We use C comments here throughout nacl_io
| |
| 5 #include <assert.h> | |
| 6 | |
| 7 #include "nacl_io/event_emitter.h" | |
|
Sam Clegg
2013/07/17 17:34:56
I think event_emitter.h is supposed to be the very
noelallen1
2013/07/17 21:00:18
Consistent with nacl_io, we could create a separat
| |
| 8 #include "nacl_io/event_listener.h" | |
| 9 | |
| 10 #include "sdk_util/auto_lock.h" | |
| 11 | |
| 12 | |
| 13 void EventEmitter::Destroy() { | |
| 14 // We can not grab the EmitterLock prior to grabbing the EventListener lock, | |
| 15 // however the ref count proves this is the only thread which has a | |
| 16 // reference to the emitter at this point so accessing events_ is safe. | |
| 17 EventInfoSet_t::iterator it; | |
| 18 for (it = events_.begin(); it != events_.end(); it++) { | |
| 19 ScopedEventInfo info = *it; | |
| 20 info->listener->AbandonedEventInfo(info); | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 void EventEmitter::RegisterEventInfo(const ScopedEventInfo& info) { | |
| 25 AutoLock lock(emitter_lock_); | |
| 26 | |
| 27 events_.insert(info); | |
| 28 ChainRegister(info); | |
| 29 } | |
| 30 | |
| 31 void EventEmitter::UnregisterEventInfo(const ScopedEventInfo& info) { | |
| 32 AutoLock lock(emitter_lock_); | |
| 33 | |
| 34 ChainUnregister(info); | |
| 35 events_.erase(info); | |
| 36 } | |
| 37 | |
| 38 void EventEmitter::RaiseEvent(uint32_t event_bits) { | |
| 39 AutoLock lock(emitter_lock_); | |
| 40 | |
| 41 EventInfoSet_t::iterator it; | |
| 42 for (it = events_.begin(); it != events_.end(); it++) { | |
| 43 // If this event is allowed by the filter, signal it | |
| 44 ScopedEventInfo info = *it; | |
| 45 if (info->filter & event_bits) { | |
| 46 info->events |= event_bits; | |
| 47 info->listener->Signal(info); | |
| 48 } | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 // Provided to allow one EventEmitter to register the same EventInfo with | |
|
binji
2013/07/17 22:23:20
might be more valuable to move this comment to the
noelallen1
2013/07/18 22:18:16
Done.
| |
| 53 // a child EventEmitter so that they can both signal the EventListener. | |
| 54 void EventEmitter::ChainRegister(const ScopedEventInfo& info) {} | |
| 55 void EventEmitter::ChainUnregister(const ScopedEventInfo& info) {} | |
| OLD | NEW |