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

Side by Side Diff: mojo/edk/system/awakable_list.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/awakable.cc ('k') | mojo/edk/system/awakable_list.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_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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 14 matching lines...) Expand all
25 // is owned by the secondary object (see simple_dispatcher.* and the explanatory 25 // is owned by the secondary object (see simple_dispatcher.* and the explanatory
26 // comment in core.cc). This class is thread-unsafe (all concurrent access must 26 // comment in core.cc). This class is thread-unsafe (all concurrent access must
27 // be protected by some lock). 27 // be protected by some lock).
28 class AwakableList { 28 class AwakableList {
29 public: 29 public:
30 AwakableList(); 30 AwakableList();
31 ~AwakableList(); 31 ~AwakableList();
32 32
33 void OnStateChange(const HandleSignalsState& old_state, 33 void OnStateChange(const HandleSignalsState& old_state,
34 const HandleSignalsState& new_state); 34 const HandleSignalsState& new_state);
35 void CancelAll(); 35 // This will awake all awakables with |Awakable::AwakeReason::CANCELLED|, and
36 // remove all awakes.
37 void CancelAndRemoveAll();
36 38
37 // Adds an awakable, identified by its pointer and its context. 39 // Adds an awakable, identified by its pointer and its context.
38 void Add(Awakable* awakable, uint64_t context, MojoHandleSignals signals); 40 //
41 // An awakable may either be persistent or one-shot (non-persistent).
42 // - A one-shot's |Awake()| will be called at most once per |Add()|, and
43 // will only be called if a watched signal goes from unsatisfied to
44 // satisfied (|Awake()| will be called with reason
45 // |Awakable::AwakeReason::SATISFIED|), all watched signals become
46 // never-satisfiable (|Awakable::AwakeReason::UNSATISFIABLE|), or
47 // |CancelAndRemoveAll()| is called (|Awakable::AwakeReason::CANCELLED|).
48 // - A persistent awakable's |Awake()| will be called for all state changes
49 // on watched signals (with reason |Awakable::AwakeReason::CHANGED|) until
50 // |CancelAndRemoveAll()| is called (at which point its |Awake()| will be
51 // called a final time with reason |Awakable::AwakeReason::CANCELLED|).
52 void Add(Awakable* awakable,
53 uint64_t context,
54 bool persistent,
55 MojoHandleSignals signals);
39 56
40 // Removes all awakables matching the given pointer and, if |match_context| is 57 // Removes all awakables matching the given pointer and, if |match_context| is
41 // true, the given context. 58 // true, the given context.
42 void Remove(bool match_context, Awakable* awakable, uint64_t context); 59 void Remove(bool match_context, Awakable* awakable, uint64_t context);
43 60
44 private: 61 private:
45 struct AwakeInfo { 62 struct AwakeInfo {
46 AwakeInfo(Awakable* awakable, MojoHandleSignals signals, uint64_t context) 63 AwakeInfo(Awakable* awakable,
47 : awakable(awakable), signals(signals), context(context) {} 64 uint64_t context,
65 bool persistent,
66 MojoHandleSignals signals)
67 : awakable(awakable),
68 context(context),
69 persistent(persistent),
70 signals(signals) {}
48 71
49 Awakable* awakable; 72 Awakable* awakable;
73 uint64_t context;
74 bool persistent;
50 MojoHandleSignals signals; 75 MojoHandleSignals signals;
51 uint64_t context;
52 }; 76 };
53 using AwakeInfoList = std::vector<AwakeInfo>; 77 using AwakeInfoList = std::vector<AwakeInfo>;
54 78
55 AwakeInfoList awakables_; 79 AwakeInfoList awakables_;
56 80
57 MOJO_DISALLOW_COPY_AND_ASSIGN(AwakableList); 81 MOJO_DISALLOW_COPY_AND_ASSIGN(AwakableList);
58 }; 82 };
59 83
60 } // namespace system 84 } // namespace system
61 } // namespace mojo 85 } // namespace mojo
62 86
63 #endif // MOJO_EDK_SYSTEM_AWAKABLE_LIST_H_ 87 #endif // MOJO_EDK_SYSTEM_AWAKABLE_LIST_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/awakable.cc ('k') | mojo/edk/system/awakable_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698