| 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_H_ | 5 #ifndef MOJO_EDK_SYSTEM_AWAKABLE_H_ |
| 6 #define MOJO_EDK_SYSTEM_AWAKABLE_H_ | 6 #define MOJO_EDK_SYSTEM_AWAKABLE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "mojo/edk/system/handle_signals_state.h" | 10 #include "mojo/edk/system/handle_signals_state.h" |
| 11 #include "mojo/public/c/system/result.h" | 11 #include "mojo/public/c/system/result.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 namespace system { | 14 namespace system { |
| 15 | 15 |
| 16 // An interface for things that may be awoken. E.g., |Waiter| is an | 16 // An interface for things that may be awoken. E.g., |Waiter| is an |
| 17 // implementation that blocks while waiting to be awoken. | 17 // implementation that blocks while waiting to be awoken. |
| 18 class Awakable { | 18 class Awakable { |
| 19 public: | 19 public: |
| 20 enum class AwakeReason { SATISFIED, UNSATISFIABLE, CANCELLED }; | 20 // See |AwakableList| (in particular its |Add()| method). |
| 21 enum class AwakeReason { SATISFIED, UNSATISFIABLE, CANCELLED, CHANGED }; |
| 21 | 22 |
| 22 // Helper function that translates: | 23 // Helper function that translates: |
| 23 // - |AwakeReason::SATISFIED| -> |MOJO_RESULT_OK|, | 24 // - |AwakeReason::SATISFIED| -> |MOJO_RESULT_OK|, |
| 24 // - |AwakeReason::UNSATISFIABLE| -> |MOJO_RESULT_FAILED_PRECONDITION|, and | 25 // - |AwakeReason::UNSATISFIABLE| -> |MOJO_RESULT_FAILED_PRECONDITION|, and |
| 25 // - |AwakeReason::CANCELLED| -> |MOJO_RESULT_CANCELLED|. | 26 // - |AwakeReason::CANCELLED| -> |MOJO_RESULT_CANCELLED|. |
| 27 // - |AwakeReason::CHANGED| -> |MOJO_RESULT_INTERNAL| (this function never |
| 28 // be called with this reason). |
| 26 static MojoResult MojoResultForAwakeReason(AwakeReason reason); | 29 static MojoResult MojoResultForAwakeReason(AwakeReason reason); |
| 27 | 30 |
| 28 // |Awake()| must satisfy the following contract: | 31 // |Awake()| must satisfy the following contract: |
| 29 // - It must be thread-safe. | 32 // - It must be thread-safe. |
| 30 // - Since it is called with a mutex held, it must not call anything that | 33 // - Since it is called with a mutex held, it must not call anything that |
| 31 // takes "non-terminal" locks, i.e., those which are always safe to take. | 34 // takes "non-terminal" locks, i.e., those which are always safe to take. |
| 32 // - It should return false if it must not be called again for the same | 35 // If |reason| is |AwakeReason::CANCELLED|, |Awake()| will not be called |
| 33 // reason (e.g., for the same call to |AwakableList::Add()|). | 36 // again (by the same source). |
| 34 virtual bool Awake(uint64_t context, | 37 virtual void Awake(uint64_t context, |
| 35 AwakeReason reason, | 38 AwakeReason reason, |
| 36 const HandleSignalsState& signals_state) = 0; | 39 const HandleSignalsState& signals_state) = 0; |
| 37 | 40 |
| 38 protected: | 41 protected: |
| 39 Awakable() {} | 42 Awakable() {} |
| 40 virtual ~Awakable() {} | 43 virtual ~Awakable() {} |
| 41 }; | 44 }; |
| 42 | 45 |
| 43 } // namespace system | 46 } // namespace system |
| 44 } // namespace mojo | 47 } // namespace mojo |
| 45 | 48 |
| 46 #endif // MOJO_EDK_SYSTEM_AWAKABLE_H_ | 49 #endif // MOJO_EDK_SYSTEM_AWAKABLE_H_ |
| OLD | NEW |