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 */ |
| 5 #include <assert.h> |
| 6 |
| 7 #include "nacl_io/event_emitter.h" |
| 8 #include "nacl_io/event_listener.h" |
| 9 |
| 10 #include "sdk_util/auto_lock.h" |
| 11 |
| 12 bool operator<(const ScopedEventInfo& src_a, const ScopedEventInfo& src_b) { |
| 13 return src_a.get() < src_b.get(); |
| 14 } |
| 15 |
| 16 void EventEmitter::Destroy() { |
| 17 // We can not grab the EmitterLock prior to grabbing the EventListener lock, |
| 18 // however the ref count proves this is the only thread which has a |
| 19 // reference to the emitter at this point so accessing events_ is safe. |
| 20 EventInfoSet_t::iterator it; |
| 21 for (it = events_.begin(); it != events_.end(); it++) { |
| 22 ScopedEventInfo info = *it; |
| 23 info->listener->AbandonedEventInfo(info); |
| 24 } |
| 25 } |
| 26 |
| 27 void EventEmitter::RegisterEventInfo(const ScopedEventInfo& info) { |
| 28 AutoLock lock(emitter_lock_); |
| 29 |
| 30 events_.insert(info); |
| 31 ChainRegister(info); |
| 32 } |
| 33 |
| 34 void EventEmitter::UnregisterEventInfo(const ScopedEventInfo& info) { |
| 35 AutoLock lock(emitter_lock_); |
| 36 |
| 37 ChainUnregister(info); |
| 38 events_.erase(info); |
| 39 } |
| 40 void EventEmitter::RaiseEvent(uint32_t event_bits) { |
| 41 AutoLock lock(emitter_lock_); |
| 42 |
| 43 EventInfoSet_t::iterator it; |
| 44 for (it = events_.begin(); it != events_.end(); it++) { |
| 45 // If this event is allowed by the filter, signal it |
| 46 ScopedEventInfo info = *it; |
| 47 if (info->filter & event_bits) { |
| 48 info->events |= event_bits & info->filter; |
| 49 info->listener->Signal(info); |
| 50 } |
| 51 } |
| 52 } |
| 53 |
| 54 void EventEmitter::ChainRegister(const ScopedEventInfo& info) {} |
| 55 void EventEmitter::ChainUnregister(const ScopedEventInfo& info) {} |
OLD | NEW |