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

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

Issue 2090763002: AwakableList: For persistent awakables, make Add() call Awake() with reason INITIALIZE. (Closed) Base URL: https://github.com/domokit/mojo.git@work795_wait_set_4.7-x-work794_wait_set_4.6
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 | « no previous file | 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 // See |AwakableList| (in particular its |Add()| method). 20 // See |AwakableList| (in particular its |Add()| method) for information about
21 enum class AwakeReason { SATISFIED, UNSATISFIABLE, CANCELLED, CHANGED }; 21 // persistent versus one-shot awakables.
22 enum class AwakeReason {
23 // Sent to both persistent and one-shot awakables (after |Awake()| is
24 // called with this, it will no longer be called by the same source):
25 CANCELLED,
26 // Sent to one-shot awakables:
27 SATISFIED,
28 UNSATISFIABLE,
29 // Sent to persistent awakables:
30 INITIALIZE,
31 CHANGED,
32 };
22 33
23 // Helper function that translates: 34 // Helper function that translates:
35 // - |AwakeReason::CANCELLED| -> |MOJO_RESULT_CANCELLED|.
24 // - |AwakeReason::SATISFIED| -> |MOJO_RESULT_OK|, 36 // - |AwakeReason::SATISFIED| -> |MOJO_RESULT_OK|,
25 // - |AwakeReason::UNSATISFIABLE| -> |MOJO_RESULT_FAILED_PRECONDITION|, and 37 // - |AwakeReason::UNSATISFIABLE| -> |MOJO_RESULT_FAILED_PRECONDITION|, and
26 // - |AwakeReason::CANCELLED| -> |MOJO_RESULT_CANCELLED|. 38 // - |AwakeReason::INITIALIZE| -> |MOJO_RESULT_INTERNAL| (this function
39 // never be called with this reason).
27 // - |AwakeReason::CHANGED| -> |MOJO_RESULT_INTERNAL| (this function never 40 // - |AwakeReason::CHANGED| -> |MOJO_RESULT_INTERNAL| (this function never
28 // be called with this reason). 41 // be called with this reason).
29 static MojoResult MojoResultForAwakeReason(AwakeReason reason); 42 static MojoResult MojoResultForAwakeReason(AwakeReason reason);
30 43
31 // |Awake()| must satisfy the following contract: 44 // |Awake()| must satisfy the following contract:
32 // - It must be thread-safe. 45 // - It must be thread-safe.
33 // - Since it is called with a mutex held, it must not call anything that 46 // - Since it is called with a mutex held, it must not call anything that
34 // takes "non-terminal" locks, i.e., those which are always safe to take. 47 // takes "non-terminal" locks, i.e., those which are always safe to take.
35 // If |reason| is |AwakeReason::CANCELLED|, |Awake()| will not be called 48 // If |reason| is |AwakeReason::CANCELLED|, |Awake()| will not be called
36 // again (by the same source). 49 // again (by the same source).
37 virtual void Awake(uint64_t context, 50 virtual void Awake(uint64_t context,
38 AwakeReason reason, 51 AwakeReason reason,
39 const HandleSignalsState& signals_state) = 0; 52 const HandleSignalsState& signals_state) = 0;
40 53
41 protected: 54 protected:
42 Awakable() {} 55 Awakable() {}
43 virtual ~Awakable() {} 56 virtual ~Awakable() {}
44 }; 57 };
45 58
46 } // namespace system 59 } // namespace system
47 } // namespace mojo 60 } // namespace mojo
48 61
49 #endif // MOJO_EDK_SYSTEM_AWAKABLE_H_ 62 #endif // MOJO_EDK_SYSTEM_AWAKABLE_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/system/awakable.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698