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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/event_emitter.cc

Issue 23498015: [NaCl SDK] Support non blocking TCP/UDP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove event friends, rename EventListenerPoll Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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 <assert.h> 5 #include <assert.h>
6 #include <poll.h>
6 7
7 #include "nacl_io/event_emitter.h" 8 #include "nacl_io/event_emitter.h"
8 #include "nacl_io/event_listener.h" 9 #include "nacl_io/event_listener.h"
10 #include "nacl_io/fifo_interface.h"
9 11
10 #include "sdk_util/auto_lock.h" 12 #include "sdk_util/auto_lock.h"
11 13
12 namespace nacl_io { 14 namespace nacl_io {
13 15
14 bool operator<(const ScopedEventInfo& src_a, const ScopedEventInfo& src_b) { 16 bool operator<(const ScopedEventEmitter& src_a,
17 const ScopedEventEmitter& src_b) {
15 return src_a.get() < src_b.get(); 18 return src_a.get() < src_b.get();
16 } 19 }
17 20
18 void EventEmitter::Destroy() { 21 void EventEmitter::RegisterListener(EventListener* listener, uint32_t events) {
19 // We can not grab the EmitterLock prior to grabbing the EventListener lock, 22 AUTO_LOCK(emitter_lock_);
20 // however the ref count proves this is the only thread which has a 23 RegisterListener_Locked(listener, events);
21 // reference to the emitter at this point so accessing events_ is safe. 24 }
22 EventInfoSet_t::iterator it; 25
23 for (it = events_.begin(); it != events_.end(); it++) { 26 void EventEmitter::UnregisterListener(EventListener* listener) {
24 ScopedEventInfo info = *it; 27 AUTO_LOCK(emitter_lock_);
25 info->listener->AbandonedEventInfo(info); 28 UnregisterListener_Locked(listener);
29 }
30
31 void EventEmitter::RegisterListener_Locked(EventListener* listener,
32 uint32_t events) {
33 listeners_[listener] = events;
34 }
35
36 void EventEmitter::UnregisterListener_Locked(EventListener* listener) {
37 listeners_.erase(listener);
38 }
39
40 void EventEmitter::RaiseEvents_Locked(uint32_t event_bits) {
41 EventListenerMap_t::iterator it;
42 for (it = listeners_.begin(); it != listeners_.end(); it++) {
43 uint32_t bits = it->second & event_bits;
44 if (0 != bits)
45 it->first->ReceiveEvents(this, bits);
26 } 46 }
27 } 47 }
28 48
29 void EventEmitter::RegisterEventInfo(const ScopedEventInfo& info) {
30 AUTO_LOCK(emitter_lock_);
31
32 events_.insert(info);
33 ChainRegisterEventInfo(info);
34 }
35
36 void EventEmitter::UnregisterEventInfo(const ScopedEventInfo& info) {
37 AUTO_LOCK(emitter_lock_);
38
39 ChainUnregisterEventInfo(info);
40 events_.erase(info);
41 }
42 void EventEmitter::RaiseEvent(uint32_t event_bits) {
43 AUTO_LOCK(emitter_lock_);
44
45 EventInfoSet_t::iterator it;
46 for (it = events_.begin(); it != events_.end(); it++) {
47 // If this event is allowed by the filter, signal it
48 ScopedEventInfo info = *it;
49 if (info->filter & event_bits) {
50 info->events |= event_bits & info->filter;
51 info->listener->Signal(info);
52 }
53 }
54 }
55
56 void EventEmitter::ChainRegisterEventInfo(const ScopedEventInfo& info) {}
57 void EventEmitter::ChainUnregisterEventInfo(const ScopedEventInfo& info) {}
58
59 } // namespace nacl_io 49 } // namespace nacl_io
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698