Index: native_client_sdk/src/libraries/nacl_io/event_emitter.cc |
diff --git a/native_client_sdk/src/libraries/nacl_io/event_emitter.cc b/native_client_sdk/src/libraries/nacl_io/event_emitter.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c7e38f5a084de04878320bba360bcd7555d78540 |
--- /dev/null |
+++ b/native_client_sdk/src/libraries/nacl_io/event_emitter.cc |
@@ -0,0 +1,55 @@ |
+/* Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
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
|
+#include <assert.h> |
+ |
+#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
|
+#include "nacl_io/event_listener.h" |
+ |
+#include "sdk_util/auto_lock.h" |
+ |
+ |
+void EventEmitter::Destroy() { |
+ // We can not grab the EmitterLock prior to grabbing the EventListener lock, |
+ // however the ref count proves this is the only thread which has a |
+ // reference to the emitter at this point so accessing events_ is safe. |
+ EventInfoSet_t::iterator it; |
+ for (it = events_.begin(); it != events_.end(); it++) { |
+ ScopedEventInfo info = *it; |
+ info->listener->AbandonedEventInfo(info); |
+ } |
+} |
+ |
+void EventEmitter::RegisterEventInfo(const ScopedEventInfo& info) { |
+ AutoLock lock(emitter_lock_); |
+ |
+ events_.insert(info); |
+ ChainRegister(info); |
+} |
+ |
+void EventEmitter::UnregisterEventInfo(const ScopedEventInfo& info) { |
+ AutoLock lock(emitter_lock_); |
+ |
+ ChainUnregister(info); |
+ events_.erase(info); |
+} |
+ |
+void EventEmitter::RaiseEvent(uint32_t event_bits) { |
+ AutoLock lock(emitter_lock_); |
+ |
+ EventInfoSet_t::iterator it; |
+ for (it = events_.begin(); it != events_.end(); it++) { |
+ // If this event is allowed by the filter, signal it |
+ ScopedEventInfo info = *it; |
+ if (info->filter & event_bits) { |
+ info->events |= event_bits; |
+ info->listener->Signal(info); |
+ } |
+ } |
+} |
+ |
+// 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.
|
+// a child EventEmitter so that they can both signal the EventListener. |
+void EventEmitter::ChainRegister(const ScopedEventInfo& info) {} |
+void EventEmitter::ChainUnregister(const ScopedEventInfo& info) {} |