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

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

Issue 2088833003: Add different behavior to AwakableList for "persistent" vs "one-shot" awakables. (Closed) Base URL: https://github.com/domokit/mojo.git@work793_wait_set_4.5
Patch Set: Created 4 years, 6 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
« no previous file with comments | « mojo/edk/system/async_waiter.cc ('k') | mojo/edk/system/awakable.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_
OLDNEW
« no previous file with comments | « mojo/edk/system/async_waiter.cc ('k') | mojo/edk/system/awakable.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698