| OLD | NEW |
| 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 Loading... |
| 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<const 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 // |
| 91 // NOTE: This pointer is only used to index |ready_watches_| and may point to |
| 92 // an invalid object. It must therefore never be dereferenced. |
| 93 const Watch* last_watch_to_block_arming_ = nullptr; |
| 84 | 94 |
| 85 DISALLOW_COPY_AND_ASSIGN(WatcherDispatcher); | 95 DISALLOW_COPY_AND_ASSIGN(WatcherDispatcher); |
| 86 }; | 96 }; |
| 87 | 97 |
| 88 } // namespace edk | 98 } // namespace edk |
| 89 } // namespace mojo | 99 } // namespace mojo |
| 90 | 100 |
| 91 #endif // MOJO_EDK_SYSTEM_WATCHER_DISPATCHER_H_ | 101 #endif // MOJO_EDK_SYSTEM_WATCHER_DISPATCHER_H_ |
| OLD | NEW |