| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 THIRD_PARTY_MOJO_SRC_MOJO_EDK_SYSTEM_WAIT_SET_DISPATCHER_H_ | |
| 6 #define THIRD_PARTY_MOJO_SRC_MOJO_EDK_SYSTEM_WAIT_SET_DISPATCHER_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 #include <map> | |
| 10 #include <utility> | |
| 11 | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "mojo/public/cpp/system/macros.h" | |
| 14 #include "third_party/mojo/src/mojo/edk/system/awakable_list.h" | |
| 15 #include "third_party/mojo/src/mojo/edk/system/dispatcher.h" | |
| 16 #include "third_party/mojo/src/mojo/edk/system/mutex.h" | |
| 17 #include "third_party/mojo/src/mojo/edk/system/system_impl_export.h" | |
| 18 | |
| 19 namespace mojo { | |
| 20 namespace system { | |
| 21 | |
| 22 class MOJO_SYSTEM_IMPL_EXPORT WaitSetDispatcher : public Dispatcher { | |
| 23 public: | |
| 24 WaitSetDispatcher(); | |
| 25 ~WaitSetDispatcher() override; | |
| 26 | |
| 27 // |Dispatcher| public methods: | |
| 28 Type GetType() const override; | |
| 29 | |
| 30 private: | |
| 31 // Internal implementation of Awakable. | |
| 32 class Waiter; | |
| 33 | |
| 34 struct WaitState { | |
| 35 scoped_refptr<Dispatcher> dispatcher; | |
| 36 MojoHandleSignals signals; | |
| 37 uintptr_t context; | |
| 38 }; | |
| 39 | |
| 40 // |Dispatcher| protected methods: | |
| 41 void CloseImplNoLock() override; | |
| 42 void CancelAllAwakablesNoLock() override; | |
| 43 MojoResult AddAwakableImplNoLock(Awakable* awakable, | |
| 44 MojoHandleSignals signals, | |
| 45 uintptr_t context, | |
| 46 HandleSignalsState* signals_state) override; | |
| 47 void RemoveAwakableImplNoLock(Awakable* awakable, | |
| 48 HandleSignalsState* signals_state) override; | |
| 49 MojoResult AddWaitingDispatcherImplNoLock( | |
| 50 const scoped_refptr<Dispatcher>& dispatcher, | |
| 51 MojoHandleSignals signals, | |
| 52 uintptr_t context) override; | |
| 53 MojoResult RemoveWaitingDispatcherImplNoLock( | |
| 54 const scoped_refptr<Dispatcher>& dispatcher) override; | |
| 55 MojoResult GetReadyDispatchersImplNoLock( | |
| 56 UserPointer<uint32_t> count, | |
| 57 DispatcherVector* dispatchers, | |
| 58 UserPointer<MojoResult> results, | |
| 59 UserPointer<uintptr_t> contexts) override; | |
| 60 HandleSignalsState GetHandleSignalsStateImplNoLock() const override; | |
| 61 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() | |
| 62 override; | |
| 63 | |
| 64 // Signal that the dispatcher indexed by |context| has been woken up with | |
| 65 // |result| and is now ready. | |
| 66 void WakeDispatcher(MojoResult result, uintptr_t context); | |
| 67 | |
| 68 // Map of dispatchers being waited on. Key is a Dispatcher* casted to a | |
| 69 // uintptr_t, and should be treated as an opaque value and not casted back. | |
| 70 std::map<uintptr_t, WaitState> waiting_dispatchers_ MOJO_GUARDED_BY(mutex()); | |
| 71 | |
| 72 // Separate mutex that can be locked without locking |mutex()|. | |
| 73 mutable Mutex awoken_mutex_ MOJO_ACQUIRED_AFTER(mutex()); | |
| 74 // List of dispatchers that have been woken up. Any dispatcher in this queue | |
| 75 // will NOT currently be waited on. | |
| 76 std::deque<std::pair<uintptr_t, MojoResult>> awoken_queue_ | |
| 77 MOJO_GUARDED_BY(awoken_mutex_); | |
| 78 // List of dispatchers that have been woken up and retrieved on the last call | |
| 79 // to |GetReadyDispatchers()|. | |
| 80 std::deque<uintptr_t> processed_dispatchers_ MOJO_GUARDED_BY(awoken_mutex_); | |
| 81 | |
| 82 // Separate mutex that can be locked without locking |mutex()|. | |
| 83 Mutex awakable_mutex_ MOJO_ACQUIRED_AFTER(mutex()); | |
| 84 // List of dispatchers being waited on. | |
| 85 AwakableList awakable_list_ MOJO_GUARDED_BY(awakable_mutex_); | |
| 86 | |
| 87 // Waiter used to wait on dispatchers. | |
| 88 scoped_ptr<Waiter> waiter_; | |
| 89 }; | |
| 90 | |
| 91 } // namespace system | |
| 92 } // namespace mojo | |
| 93 | |
| 94 #endif // THIRD_PARTY_MOJO_SRC_MOJO_EDK_SYSTEM_WAIT_SET_DISPATCHER_H_ | |
| OLD | NEW |