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

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

Issue 2084593005: Rationalize AddAwakable...() and RemoveAwakable...() methods. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: doh 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/data_pipe_producer_dispatcher.cc ('k') | mojo/edk/system/dispatcher.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_DISPATCHER_H_ 5 #ifndef MOJO_EDK_SYSTEM_DISPATCHER_H_
6 #define MOJO_EDK_SYSTEM_DISPATCHER_H_ 6 #define MOJO_EDK_SYSTEM_DISPATCHER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // returns a default-constructed |HandleSignalsState|, i.e., no signals 186 // returns a default-constructed |HandleSignalsState|, i.e., no signals
187 // satisfied or satisfiable.) Note: The state is subject to change from other 187 // satisfied or satisfiable.) Note: The state is subject to change from other
188 // threads. 188 // threads.
189 HandleSignalsState GetHandleSignalsState() const; 189 HandleSignalsState GetHandleSignalsState() const;
190 190
191 // Adds an awakable to this dispatcher, which will be woken up when this 191 // Adds an awakable to this dispatcher, which will be woken up when this
192 // object changes state to satisfy |signals| with context |context|. It will 192 // object changes state to satisfy |signals| with context |context|. It will
193 // also be woken up when it becomes impossible for the object to ever satisfy 193 // also be woken up when it becomes impossible for the object to ever satisfy
194 // |signals| with a suitable error status. 194 // |signals| with a suitable error status.
195 // 195 //
196 // If |force| is true, the awakable will be added even if |signals| is already
197 // satisfied or is never-satisfiable (if it is possible that some other change
198 // will cause it to become satisfiable again).
199 //
196 // If |signals_state| is non-null, |*signals_state| will be set to the current 200 // If |signals_state| is non-null, |*signals_state| will be set to the current
197 // handle signals state. 201 // handle signals state.
198 // 202 //
199 // Any awakable that's added must either eventually be removed (using 203 // Any awakable that's added must either eventually be removed (using
200 // |RemoveAwakable()| or |RemoveAwakableWithContext()|, below). If an 204 // |RemoveAwakable()|, below). If an awakable's |Awake()| is called (by this
201 // awakable's |Awake()| is called (by this dispatcher) and it returns false, 205 // dispatcher) and it returns false, that is equivalent to |RemoveAwakable()|
202 // that is equivalent to |RemoveAwakableWithContext()| being called for that 206 // being called (with |match_context| true) for that awakable and the context
203 // awakable and the context passed to |Awake()|. 207 // passed to |Awake()|.
204 // 208 //
205 // Returns: 209 // Returns:
206 // - |MOJO_RESULT_OK| if the awakable was added; 210 // - |MOJO_RESULT_OK| if the awakable was added;
207 // - |MOJO_RESULT_ALREADY_EXISTS| if |signals| is already satisfied (if 211 // - |MOJO_RESULT_ALREADY_EXISTS| if |signals| is already satisfied (if
208 // |force| is true, the awakable will still be added); 212 // |force| is true, the awakable will still be added);
209 // - |MOJO_RESULT_INVALID_ARGUMENT| if the dispatcher has been closed; and 213 // - |MOJO_RESULT_INVALID_ARGUMENT| if the dispatcher has been closed; and
210 // - |MOJO_RESULT_FAILED_PRECONDITION| if it is not (or no longer) possible 214 // - |MOJO_RESULT_FAILED_PRECONDITION| if it is not (or no longer) possible
211 // that |signals| will ever be satisfied. 215 // that |signals| will ever be satisfied(if |force| is true, the awakable
216 // will still be added).
212 MojoResult AddAwakable(Awakable* awakable, 217 MojoResult AddAwakable(Awakable* awakable,
218 uint64_t context,
219 bool force,
213 MojoHandleSignals signals, 220 MojoHandleSignals signals,
214 uint64_t context,
215 HandleSignalsState* signals_state); 221 HandleSignalsState* signals_state);
216 // Like |AddAwakable()|, but in the |MOJO_RESULT_ALREADY_EXISTS| case still 222 // Removes an awakable from this dispatcher. This will remove all instances
217 // adds the awakable (|MOJO_RESULT_ALREADY_EXISTS| will still be returned). 223 // matching the awakable pointer and, if |match_context| is true, the context
218 MojoResult AddAwakableUnconditional(Awakable* awakable, 224 // (if |match_context| is false, |context| is ignored). It is valid to call
219 MojoHandleSignals signals, 225 // this multiple times for the same |awakable| on the same object.) If
220 uint64_t context, 226 // |signals_state| is non-null, |*signals_state| will be set to the current
221 HandleSignalsState* signals_state); 227 // handle signals state.
222 // Removes an awakable from this dispatcher. This will remove all instances of 228 void RemoveAwakable(bool match_context,
223 // |awakable|, regardless of context. (It is valid to call this multiple times 229 Awakable* awakable,
224 // for the same |awakable| on the same object.) If |signals_state| is 230 uint64_t context,
225 // non-null, |*signals_state| will be set to the current handle signals state. 231 HandleSignalsState* signals_state);
226 void RemoveAwakable(Awakable* awakable, HandleSignalsState* signals_state);
227 // Like |RemoveAwakable()|, but only removes "instances" with the given
228 // context. (This may also be called multiple times, and there may be multiple
229 // instances with the same context.)
230 void RemoveAwakableWithContext(Awakable* awakable,
231 uint64_t context,
232 HandleSignalsState* signals_state);
233 232
234 // A dispatcher must be put into a special state in order to be sent across a 233 // A dispatcher must be put into a special state in order to be sent across a
235 // message pipe. Outside of tests, only |HandleTableAccess| is allowed to do 234 // message pipe. Outside of tests, only |HandleTableAccess| is allowed to do
236 // this, since there are requirements on the handle table (see below). 235 // this, since there are requirements on the handle table (see below).
237 // 236 //
238 // In this special state, only a restricted set of operations is allowed. 237 // In this special state, only a restricted set of operations is allowed.
239 // These are the ones available as |HandleTransport| methods. Other 238 // These are the ones available as |HandleTransport| methods. Other
240 // |Dispatcher| methods must not be called until |HandleTransport::End()| has 239 // |Dispatcher| methods must not be called until |HandleTransport::End()| has
241 // been called. 240 // been called.
242 class HandleTableAccess { 241 class HandleTableAccess {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 MojoHandleSignals signals, 392 MojoHandleSignals signals,
394 uint64_t cookie); 393 uint64_t cookie);
395 virtual MojoResult WaitSetRemoveImpl(uint64_t cookie); 394 virtual MojoResult WaitSetRemoveImpl(uint64_t cookie);
396 virtual MojoResult WaitSetWaitImpl(MojoDeadline deadline, 395 virtual MojoResult WaitSetWaitImpl(MojoDeadline deadline,
397 UserPointer<uint32_t> num_results, 396 UserPointer<uint32_t> num_results,
398 UserPointer<MojoWaitSetResult> results, 397 UserPointer<MojoWaitSetResult> results,
399 UserPointer<uint32_t> max_results); 398 UserPointer<uint32_t> max_results);
400 virtual HandleSignalsState GetHandleSignalsStateImplNoLock() const 399 virtual HandleSignalsState GetHandleSignalsStateImplNoLock() const
401 MOJO_SHARED_LOCKS_REQUIRED(mutex_); 400 MOJO_SHARED_LOCKS_REQUIRED(mutex_);
402 virtual MojoResult AddAwakableImplNoLock(Awakable* awakable, 401 virtual MojoResult AddAwakableImplNoLock(Awakable* awakable,
402 uint64_t context,
403 bool force,
403 MojoHandleSignals signals, 404 MojoHandleSignals signals,
404 bool force,
405 uint64_t context,
406 HandleSignalsState* signals_state) 405 HandleSignalsState* signals_state)
407 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 406 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
408 virtual void RemoveAwakableImplNoLock(Awakable* awakable, 407 virtual void RemoveAwakableImplNoLock(bool match_context,
408 Awakable* awakable,
409 uint64_t context,
409 HandleSignalsState* signals_state) 410 HandleSignalsState* signals_state)
410 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 411 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
411 virtual void RemoveAwakableWithContextImplNoLock(
412 Awakable* awakable,
413 uint64_t context,
414 HandleSignalsState* signals_state) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
415 412
416 // These implement the API used to serialize dispatchers to a |Channel| 413 // These implement the API used to serialize dispatchers to a |Channel|
417 // (described below). They will only be called on a dispatcher that's attached 414 // (described below). They will only be called on a dispatcher that's attached
418 // to and "owned" by a |MessageInTransit|. See the non-"impl" versions for 415 // to and "owned" by a |MessageInTransit|. See the non-"impl" versions for
419 // more information. 416 // more information.
420 // 417 //
421 // Note: |StartSerializeImplNoLock()| is actually called with |mutex_| NOT 418 // Note: |StartSerializeImplNoLock()| is actually called with |mutex_| NOT
422 // held, since the dispatcher should only be accessible to the calling thread. 419 // held, since the dispatcher should only be accessible to the calling thread.
423 // On Debug builds, |EndSerializeAndCloseImplNoLock()| is called with |mutex_| 420 // On Debug builds, |EndSerializeAndCloseImplNoLock()| is called with |mutex_|
424 // held, to satisfy any |mutex_.AssertHeld()| (e.g., in |CloseImplNoLock()| -- 421 // held, to satisfy any |mutex_.AssertHeld()| (e.g., in |CloseImplNoLock()| --
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 514
518 // So logging macros and |DCHECK_EQ()|, etc. work. 515 // So logging macros and |DCHECK_EQ()|, etc. work.
519 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { 516 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) {
520 return out << static_cast<int>(type); 517 return out << static_cast<int>(type);
521 } 518 }
522 519
523 } // namespace system 520 } // namespace system
524 } // namespace mojo 521 } // namespace mojo
525 522
526 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ 523 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/data_pipe_producer_dispatcher.cc ('k') | mojo/edk/system/dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698