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