| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_AWAKABLE_LIST_H_ | 5 #ifndef MOJO_EDK_SYSTEM_AWAKABLE_LIST_H_ |
| 6 #define MOJO_EDK_SYSTEM_AWAKABLE_LIST_H_ | 6 #define MOJO_EDK_SYSTEM_AWAKABLE_LIST_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "mojo/edk/system/system_impl_export.h" | 14 #include "mojo/edk/system/system_impl_export.h" |
| 15 #include "mojo/edk/system/watcher.h" | |
| 16 #include "mojo/edk/system/watcher_set.h" | |
| 17 #include "mojo/public/c/system/types.h" | 15 #include "mojo/public/c/system/types.h" |
| 18 | 16 |
| 19 namespace mojo { | 17 namespace mojo { |
| 20 namespace edk { | 18 namespace edk { |
| 21 | 19 |
| 22 class Awakable; | 20 class Awakable; |
| 23 struct HandleSignalsState; | 21 struct HandleSignalsState; |
| 24 | 22 |
| 25 // |AwakableList| tracks all the |Waiter|s that are waiting on a given | 23 // |AwakableList| tracks all the |Waiter|s that are waiting on a given |
| 26 // handle/|Dispatcher|. There should be a |AwakableList| for each handle that | 24 // handle/|Dispatcher|. There should be a |AwakableList| for each handle that |
| 27 // can be waited on (in any way). In the simple case, the |AwakableList| is | 25 // can be waited on (in any way). In the simple case, the |AwakableList| is |
| 28 // owned by the |Dispatcher|, whereas in more complex cases it is owned by the | 26 // owned by the |Dispatcher|, whereas in more complex cases it is owned by the |
| 29 // secondary object (see simple_dispatcher.* and the explanatory comment in | 27 // secondary object (see simple_dispatcher.* and the explanatory comment in |
| 30 // core.cc). This class is thread-unsafe (all concurrent access must be | 28 // core.cc). This class is thread-unsafe (all concurrent access must be |
| 31 // protected by some lock). | 29 // protected by some lock). |
| 32 class MOJO_SYSTEM_IMPL_EXPORT AwakableList { | 30 class MOJO_SYSTEM_IMPL_EXPORT AwakableList { |
| 33 public: | 31 public: |
| 34 AwakableList(); | 32 AwakableList(); |
| 35 ~AwakableList(); | 33 ~AwakableList(); |
| 36 | 34 |
| 37 void AwakeForStateChange(const HandleSignalsState& state); | 35 void AwakeForStateChange(const HandleSignalsState& state); |
| 38 void CancelAll(); | 36 void CancelAll(); |
| 39 void Add(Awakable* awakable, MojoHandleSignals signals, uintptr_t context); | 37 void Add(Awakable* awakable, MojoHandleSignals signals, uintptr_t context); |
| 40 void Remove(Awakable* awakable); | 38 void Remove(Awakable* awakable); |
| 41 | 39 |
| 42 // Add and remove Watchers to this AwakableList. | |
| 43 MojoResult AddWatcher(MojoHandleSignals signals, | |
| 44 const Watcher::WatchCallback& callback, | |
| 45 uintptr_t context, | |
| 46 const HandleSignalsState& current_state); | |
| 47 MojoResult RemoveWatcher(uintptr_t context); | |
| 48 | |
| 49 private: | 40 private: |
| 50 struct AwakeInfo { | 41 struct AwakeInfo { |
| 51 AwakeInfo(Awakable* awakable, MojoHandleSignals signals, uintptr_t context) | 42 AwakeInfo(Awakable* awakable, MojoHandleSignals signals, uintptr_t context) |
| 52 : awakable(awakable), signals(signals), context(context) {} | 43 : awakable(awakable), signals(signals), context(context) {} |
| 53 | 44 |
| 54 Awakable* awakable; | 45 Awakable* awakable; |
| 55 MojoHandleSignals signals; | 46 MojoHandleSignals signals; |
| 56 uintptr_t context; | 47 uintptr_t context; |
| 57 }; | 48 }; |
| 58 using AwakeInfoList = std::vector<AwakeInfo>; | 49 using AwakeInfoList = std::vector<AwakeInfo>; |
| 59 | 50 |
| 60 AwakeInfoList awakables_; | 51 AwakeInfoList awakables_; |
| 61 | 52 |
| 62 // TODO: Remove AwakableList and instead use WatcherSet directly in | |
| 63 // dispatchers. | |
| 64 WatcherSet watchers_; | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(AwakableList); | 53 DISALLOW_COPY_AND_ASSIGN(AwakableList); |
| 67 }; | 54 }; |
| 68 | 55 |
| 69 } // namespace edk | 56 } // namespace edk |
| 70 } // namespace mojo | 57 } // namespace mojo |
| 71 | 58 |
| 72 #endif // MOJO_EDK_SYSTEM_AWAKABLE_LIST_H_ | 59 #endif // MOJO_EDK_SYSTEM_AWAKABLE_LIST_H_ |
| OLD | NEW |