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

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

Issue 19271009: [NaCl SDK} Add EventListener and EventEmitter to support epoll. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Missing stdint for windows Created 7 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 | Annotate | Revision Log
OLDNEW
(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 #ifndef LIBRARIES_NACL_IO_EVENT_EMITTER_H_
6 #define LIBRARIES_NACL_IO_EVENT_EMITTER_H_
7
8 #include <stdint.h>
9
10 #include <map>
11 #include <set>
12
13 #include "nacl_io/error.h"
14
15 #include "sdk_util/ref_object.h"
16 #include "sdk_util/scoped_ref.h"
17 #include "sdk_util/simple_lock.h"
18
19 class EventEmitter;
20 class EventInfo;
21 class EventListener;
22
23 // A ref counted object for storing the state of a single signal request.
24 // Requests are unique to any FD/EventListener pair.
25 struct EventInfo : public RefObject {
26 uint64_t user_data;
27 uint32_t events;
28 uint32_t filter;
29 // We do not use a ScopedRef to prevent circular references.
30 EventEmitter* emitter;
31 EventListener* listener;
32 uint32_t id;
33 };
34
35 typedef ScopedRef<EventInfo> ScopedEventInfo;
36
37 // Provide comparison for std::map and std::set
38 bool operator<(const ScopedEventInfo& src_a, const ScopedEventInfo& src_b);
39
40 typedef std::map<int, ScopedEventInfo> EventInfoMap_t;
41 typedef std::set<ScopedEventInfo> EventInfoSet_t;
42
43 // EventEmitter
44 //
45 // The EventEmitter class provides notification of events to EventListeners
46 // by registering EventInfo objects and signalling the EventListener when
47 // ever thier state is changed.
48 //
49 // See "Kernel Events" in event_listener.h for additional information.
50 class EventEmitter : public RefObject {
51 typedef std::set<ScopedEventInfo> EventInfoSet_t;
52
53 protected:
54 // Called automatically prior to delete to inform the EventListeners that
55 // this EventEmitter is abandoning an associated EventInfo.
56 virtual void Destroy();
57
58 private:
59 // Regisiter or unregister an EventInfo. The lock of the EventListener
60 // associated with this EventInfo must be held prior to calling these
61 // functions. These functions are private to ensure they are called by the
62 // EventListener.
63 void RegisterEventInfo(const ScopedEventInfo& info);
64 void UnregisterEventInfo(const ScopedEventInfo& info);
65
66 public:
67 // Returns the current state of the emitter.
68 virtual uint32_t GetEventStatus() = 0;
69
70 // REturns the type of the emitter (compatible with st_mode in stat)
71 virtual int GetType() = 0;
72
73 protected:
74 // Called by the thread causing the Event.
75 void RaiseEvent(uint32_t events);
76
77 // Provided to allow one EventEmitter to register the same EventInfo with
78 // a child EventEmitter so that they can both signal the EventListener.
79 // Called after registering locally, but while lock is still held.
80 virtual void ChainRegister(const ScopedEventInfo& event);
81
82 // Called before unregistering locally, but while lock is still held.
83 virtual void ChainUnregister(const ScopedEventInfo& event);
84
85 private:
86 SimpleLock emitter_lock_;
87 EventInfoSet_t events_;
88 friend class EventListener;
89 };
90
91 typedef ScopedRef<EventEmitter> ScopedEventEmitter;
92
93 #endif // LIBRARIES_NACL_IO_EVENT_EMITTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698