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

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

Issue 2754083003: Mojo EDK: Circulate MojoArmWatcher outputs to avoid starvation (Closed)
Patch Set: . Created 3 years, 9 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 MOJO_EDK_SYSTEM_WATCHER_DISPATCHER_H_ 5 #ifndef MOJO_EDK_SYSTEM_WATCHER_DISPATCHER_H_
6 #define MOJO_EDK_SYSTEM_WATCHER_DISPATCHER_H_ 6 #define MOJO_EDK_SYSTEM_WATCHER_DISPATCHER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 uintptr_t context) override; 48 uintptr_t context) override;
49 MojoResult CancelWatch(uintptr_t context) override; 49 MojoResult CancelWatch(uintptr_t context) override;
50 MojoResult Arm(uint32_t* num_ready_contexts, 50 MojoResult Arm(uint32_t* num_ready_contexts,
51 uintptr_t* ready_contexts, 51 uintptr_t* ready_contexts,
52 MojoResult* ready_results, 52 MojoResult* ready_results,
53 MojoHandleSignalsState* ready_signals_states) override; 53 MojoHandleSignalsState* ready_signals_states) override;
54 54
55 private: 55 private:
56 friend class Watch; 56 friend class Watch;
57 57
58 using WatchSet = std::set<Watch*>;
59
58 ~WatcherDispatcher() override; 60 ~WatcherDispatcher() override;
59 61
60 const MojoWatcherCallback callback_; 62 const MojoWatcherCallback callback_;
61 63
62 // Guards access to the fields below. 64 // Guards access to the fields below.
63 // 65 //
64 // NOTE: This may be acquired while holding another dispatcher's lock, as 66 // NOTE: This may be acquired while holding another dispatcher's lock, as
65 // watched dispatchers call into WatcherDispatcher methods which lock this 67 // watched dispatchers call into WatcherDispatcher methods which lock this
66 // when issuing state change notifications. WatcherDispatcher must therefore 68 // when issuing state change notifications. WatcherDispatcher must therefore
67 // take caution to NEVER acquire other dispatcher locks while this is held. 69 // take caution to NEVER acquire other dispatcher locks while this is held.
68 base::Lock lock_; 70 base::Lock lock_;
69 71
70 bool armed_ = false; 72 bool armed_ = false;
71 bool closed_ = false; 73 bool closed_ = false;
72 74
73 // A mapping from context to Watch. 75 // A mapping from context to Watch.
74 std::map<uintptr_t, scoped_refptr<Watch>> watches_; 76 std::map<uintptr_t, scoped_refptr<Watch>> watches_;
75 77
76 // A mapping from watched dispatcher to Watch. 78 // A mapping from watched dispatcher to Watch.
77 std::map<Dispatcher*, scoped_refptr<Watch>> watched_handles_; 79 std::map<Dispatcher*, scoped_refptr<Watch>> watched_handles_;
78 80
79 // The set of all Watch instances which are currently ready to signal. This is 81 // The set of all Watch instances which are currently ready to signal. This is
80 // used for efficient arming behavior, as it allows for O(1) discovery of 82 // used for efficient arming behavior, as it allows for O(1) discovery of
81 // whether or not arming can succeed and quick determination of who's 83 // whether or not arming can succeed and quick determination of who's
82 // responsible if it can't. 84 // responsible if it can't.
83 std::set<Watch*> ready_watches_; 85 WatchSet ready_watches_;
86
87 // Tracks the last Watch whose state was returned by Arm(). This is used to
88 // ensure consistent round-robin behavior in the event that multiple Watches
89 // remain ready over the span of several Arm() attempts.
90 Watch* last_watch_to_block_arming_ = nullptr;
yzshen1 2017/03/16 18:59:01 Please comment that this pointer may not refer to
Ken Rockot(use gerrit already) 2017/03/16 19:21:11 Done
84 91
85 DISALLOW_COPY_AND_ASSIGN(WatcherDispatcher); 92 DISALLOW_COPY_AND_ASSIGN(WatcherDispatcher);
86 }; 93 };
87 94
88 } // namespace edk 95 } // namespace edk
89 } // namespace mojo 96 } // namespace mojo
90 97
91 #endif // MOJO_EDK_SYSTEM_WATCHER_DISPATCHER_H_ 98 #endif // MOJO_EDK_SYSTEM_WATCHER_DISPATCHER_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/system/watcher_dispatcher.cc » ('j') | mojo/edk/system/watcher_dispatcher.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698