Chromium Code Reviews| Index: native_client_sdk/src/libraries/nacl_io/event_listener.h |
| diff --git a/native_client_sdk/src/libraries/nacl_io/event_listener.h b/native_client_sdk/src/libraries/nacl_io/event_listener.h |
| index cb93f116b2f1b91179e78193ba8bb9551641c45a..eb5a227c9443435cee44c882b65efc56404c9fd2 100644 |
| --- a/native_client_sdk/src/libraries/nacl_io/event_listener.h |
| +++ b/native_client_sdk/src/libraries/nacl_io/event_listener.h |
| @@ -15,6 +15,7 @@ |
| #include "nacl_io/error.h" |
| #include "nacl_io/event_emitter.h" |
| +#include "sdk_util/auto_lock.h" |
| #include "sdk_util/scoped_ref.h" |
| // Kernel Events |
| @@ -70,74 +71,89 @@ struct EventData { |
| uint64_t user_data; |
| }; |
| +struct EventRequest { |
| + ScopedEventEmitter emitter; |
| + uint32_t filter; |
| + uint32_t events; |
| +}; |
| + |
| + |
| +class EventListener; |
| +class EventListenerGroup; |
| +class EventListenerSingle; |
| + |
| +typedef std::map<EventEmitter*, EventRequest*> EmitterRequestMap_t; |
| // EventListener |
| // |
| // The EventListener class provides an object to wait on for specific events |
| // from EventEmitter objects. The EventListener becomes signalled for |
| // read when events are waiting, making it is also an Emitter. |
| -class EventListener : public EventEmitter { |
| +class EventListener { |
| public: |
| EventListener(); |
| ~EventListener(); |
| - protected: |
| - // Called prior to free to unregister all EventInfos from the EventEmitters. |
| - void Destroy(); |
| - |
| public: |
| - // Declared in EventEmitter |
| - virtual uint32_t GetEventStatus(); |
| - virtual int GetType(); |
| - |
| // Called by EventEmitter to signal the Listener that a new event is |
| // available. |
| - void Signal(const ScopedEventInfo& info); |
| + virtual void ReceiveEvents(EventEmitter* emitter, uint32_t events) = 0; |
| - // Wait for one or more previously Tracked events to take place |
| - // or until ms_timeout expires, and fills |events| up to |max| limit. |
| - // The number of events recored is returned in |count|. |
| - Error Wait(EventData* events, int max, int ms_timeout, int* out_count); |
| + protected: |
| + pthread_cond_t signal_cond_; |
| +}; |
| - // Tracks a new set of POLL events for a given unique |id|. The |
| - // |user_data| will be returned in the Wait when an event of type |filter| |
| - // is received with that |id|. |
| - Error Track(int id, |
| - const ScopedEventEmitter& emitter, |
| - uint32_t filter, |
| - uint64_t user_data); |
| - // Updates the tracking of events for |id|, replacing the |user_data| |
| - // that's returned, as well as which events will signal. |
| - Error Update(int id, uint32_t filter, uint64_t user_data); |
| +class EventListenerSingle : public EventListener { |
| + public: |
| + EventListenerSingle() : EventListener(), events_(0) {} |
| - // Unregisters the existing |id|. |
| - Error Free(int id); |
| + // Called by EventEmitter to signal the Listener that a new event is |
| + // available. |
| + virtual void ReceiveEvents(EventEmitter* emitter, uint32_t events); |
| - // Notification by EventEmitter that it is abandoning the event. Do not |
| - // access the emitter after this. |
| - void AbandonedEventInfo(const ScopedEventInfo& event); |
| + public: |
| + // Wait for the requested emitter to emit one of the events in the |
| + // |event| mask, or return error. The AutoUnlock will always hold the |
| + // event's lock, even on error. |
| + // |
| + // On Error: |
| + // ETIMEOUT if the timeout is exceeded. |
| + // EINTR if the wait was interrupted. |
| + Error WaitOnLock(EventEmitter* emitter, |
| + uint32_t events, |
| + int ms_max, |
| + sdk_util::AutoUnlock* unlock); |
| + |
| +protected: |
| + uint32_t events_; |
| +}; |
| - private: |
| - // Protects the data in the EventInfo map. |
| - sdk_util::SimpleLock info_lock_; |
| - // Map from ID to live a event info. |
| - EventInfoMap_t event_info_map_; |
| +class EventListenerGroup : public EventListener { |
| + public: |
| + EventListenerGroup() : EventListener(), signaled_(0) {} |
| - // Protects waiting_, signaled_ and used with the signal_cond_. |
| + // Called by EventEmitter to signal the Listener that a new event is |
| + // available. |
| + virtual void ReceiveEvents(EventEmitter* emitter, uint32_t events); |
| + |
| +public: |
| + // Wait for the any requested emitter/filter pairs to emit one of the |
| + // events in the matching filter. Returns 0 on success. |
| + // |
| + // On Error: |
| + // ETIMEOUT if the timeout is exceeded. |
| + // EINTR if the wait was interrupted. |
| + Error WaitOnAny(EventRequest* requests, size_t cnt, int ms_max); |
| + |
| +protected: |
| sdk_util::SimpleLock signal_lock_; |
| - pthread_cond_t signal_cond_; |
| + EmitterRequestMap_t emitters_; |
| + size_t signaled_; |
|
binji
2013/09/12 01:47:56
remove extra line
|
| - // The number of threads currently waiting on this Listener. |
| - uint32_t waiting_; |
| - |
| - // Set of event infos signaled during a wait. |
| - EventInfoSet_t signaled_; |
| }; |
| -typedef sdk_util::ScopedRef<EventListener> ScopedEventListener; |
| - |
| } // namespace nacl_io |
| #endif /* LIBRARIES_NACL_IO_EVENT_LISTENER_H_ */ |