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

Side by Side Diff: mojo/edk/system/wait_set_dispatcher.h

Issue 1504733002: Implementation of WaitSet for new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-waitset-implementation
Patch Set: Add gyp rules. Created 5 years 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
« no previous file with comments | « mojo/edk/system/dispatcher.cc ('k') | mojo/edk/system/wait_set_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 #ifndef THIRD_PARTY_MOJO_SRC_MOJO_EDK_SYSTEM_WAIT_SET_DISPATCHER_H_ 5 #ifndef MOJO_EDK_SYSTEM_WAIT_SET_DISPATCHER_H_
6 #define THIRD_PARTY_MOJO_SRC_MOJO_EDK_SYSTEM_WAIT_SET_DISPATCHER_H_ 6 #define MOJO_EDK_SYSTEM_WAIT_SET_DISPATCHER_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/synchronization/lock.h"
14 #include "mojo/edk/system/awakable_list.h"
15 #include "mojo/edk/system/dispatcher.h"
16 #include "mojo/edk/system/system_impl_export.h"
13 #include "mojo/public/cpp/system/macros.h" 17 #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 18
19 namespace mojo { 19 namespace mojo {
20 namespace system { 20 namespace edk {
21 21
22 class MOJO_SYSTEM_IMPL_EXPORT WaitSetDispatcher : public Dispatcher { 22 class MOJO_SYSTEM_IMPL_EXPORT WaitSetDispatcher : public Dispatcher {
23 public: 23 public:
24 WaitSetDispatcher(); 24 WaitSetDispatcher();
25 ~WaitSetDispatcher() override;
26 25
27 // |Dispatcher| public methods: 26 // |Dispatcher| public methods:
28 Type GetType() const override; 27 Type GetType() const override;
29 28
30 private: 29 private:
31 // Internal implementation of Awakable. 30 // Internal implementation of Awakable.
32 class Waiter; 31 class Waiter;
33 32
34 struct WaitState { 33 struct WaitState {
34 WaitState();
35 ~WaitState();
36
35 scoped_refptr<Dispatcher> dispatcher; 37 scoped_refptr<Dispatcher> dispatcher;
36 MojoHandleSignals signals; 38 MojoHandleSignals signals;
37 uintptr_t context; 39 uintptr_t context;
38 }; 40 };
39 41
42 ~WaitSetDispatcher() override;
43
40 // |Dispatcher| protected methods: 44 // |Dispatcher| protected methods:
41 void CloseImplNoLock() override; 45 void CloseImplNoLock() override;
42 void CancelAllAwakablesNoLock() override; 46 void CancelAllAwakablesNoLock() override;
43 MojoResult AddAwakableImplNoLock(Awakable* awakable, 47 MojoResult AddAwakableImplNoLock(Awakable* awakable,
44 MojoHandleSignals signals, 48 MojoHandleSignals signals,
45 uintptr_t context, 49 uintptr_t context,
46 HandleSignalsState* signals_state) override; 50 HandleSignalsState* signals_state) override;
47 void RemoveAwakableImplNoLock(Awakable* awakable, 51 void RemoveAwakableImplNoLock(Awakable* awakable,
48 HandleSignalsState* signals_state) override; 52 HandleSignalsState* signals_state) override;
49 MojoResult AddWaitingDispatcherImplNoLock( 53 MojoResult AddWaitingDispatcherImplNoLock(
50 const scoped_refptr<Dispatcher>& dispatcher, 54 const scoped_refptr<Dispatcher>& dispatcher,
51 MojoHandleSignals signals, 55 MojoHandleSignals signals,
52 uintptr_t context) override; 56 uintptr_t context) override;
53 MojoResult RemoveWaitingDispatcherImplNoLock( 57 MojoResult RemoveWaitingDispatcherImplNoLock(
54 const scoped_refptr<Dispatcher>& dispatcher) override; 58 const scoped_refptr<Dispatcher>& dispatcher) override;
55 MojoResult GetReadyDispatchersImplNoLock( 59 MojoResult GetReadyDispatchersImplNoLock(uint32_t* count,
56 UserPointer<uint32_t> count, 60 DispatcherVector* dispatchers,
57 DispatcherVector* dispatchers, 61 MojoResult* results,
58 UserPointer<MojoResult> results, 62 uintptr_t* contexts) override;
59 UserPointer<uintptr_t> contexts) override;
60 HandleSignalsState GetHandleSignalsStateImplNoLock() const override; 63 HandleSignalsState GetHandleSignalsStateImplNoLock() const override;
61 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() 64 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock()
62 override; 65 override;
63 66
64 // Signal that the dispatcher indexed by |context| has been woken up with 67 // Signal that the dispatcher indexed by |context| has been woken up with
65 // |result| and is now ready. 68 // |result| and is now ready.
66 void WakeDispatcher(MojoResult result, uintptr_t context); 69 void WakeDispatcher(MojoResult result, uintptr_t context);
67 70
68 // Map of dispatchers being waited on. Key is a Dispatcher* casted to a 71 // 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. 72 // 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()); 73 std::map<uintptr_t, WaitState> waiting_dispatchers_;
71 74
72 // Separate mutex that can be locked without locking |mutex()|. 75 // Separate lock that can be locked without locking |lock()|.
73 mutable Mutex awoken_mutex_ MOJO_ACQUIRED_AFTER(mutex()); 76 mutable base::Lock awoken_lock_;
74 // List of dispatchers that have been woken up. Any dispatcher in this queue 77 // List of dispatchers that have been woken up. Any dispatcher in this queue
75 // will NOT currently be waited on. 78 // will NOT currently be waited on.
76 std::deque<std::pair<uintptr_t, MojoResult>> awoken_queue_ 79 std::deque<std::pair<uintptr_t, MojoResult>> awoken_queue_;
77 MOJO_GUARDED_BY(awoken_mutex_); 80 // List of dispatchers that have been woken up and retrieved.
78 // List of dispatchers that have been woken up and retrieved on the last call 81 std::deque<uintptr_t> processed_dispatchers_;
79 // to |GetReadyDispatchers()|.
80 std::deque<uintptr_t> processed_dispatchers_ MOJO_GUARDED_BY(awoken_mutex_);
81 82
82 // Separate mutex that can be locked without locking |mutex()|. 83 // Separate lock that can be locked without locking |lock()|.
83 Mutex awakable_mutex_ MOJO_ACQUIRED_AFTER(mutex()); 84 base::Lock awakable_lock_;
84 // List of dispatchers being waited on. 85 // List of dispatchers being waited on.
85 AwakableList awakable_list_ MOJO_GUARDED_BY(awakable_mutex_); 86 AwakableList awakable_list_;
86 87
87 // Waiter used to wait on dispatchers. 88 // Waiter used to wait on dispatchers.
88 scoped_ptr<Waiter> waiter_; 89 scoped_ptr<Waiter> waiter_;
89 }; 90 };
90 91
91 } // namespace system 92 } // namespace edk
92 } // namespace mojo 93 } // namespace mojo
93 94
94 #endif // THIRD_PARTY_MOJO_SRC_MOJO_EDK_SYSTEM_WAIT_SET_DISPATCHER_H_ 95 #endif // MOJO_EDK_SYSTEM_WAIT_SET_DISPATCHER_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/dispatcher.cc ('k') | mojo/edk/system/wait_set_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698