| 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_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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |signals_state| is non-null, on *failure* |*signals_state| will be set | 196 // If |signals_state| is non-null, on *failure* |*signals_state| will be set |
| 197 // to the current handle signals state (on success, it is left untouched). | 197 // to the current handle signals state (on success, it is left untouched). |
| 198 // | 198 // |
| 199 // Any awakable that's added must either eventually be removed (using |
| 200 // |RemoveAwakable()| or |RemoveAwakableWithContext()|, below). If an |
| 201 // awakable's |Awake()| is called (by this dispatcher) and it returns false, |
| 202 // that is equivalent to |RemoveAwakableWithContext()| being called for that |
| 203 // awakable and the context passed to |Awake()|. |
| 204 // |
| 199 // Returns: | 205 // Returns: |
| 200 // - |MOJO_RESULT_OK| if the awakable was added; | 206 // - |MOJO_RESULT_OK| if the awakable was added; |
| 201 // - |MOJO_RESULT_ALREADY_EXISTS| if |signals| is already satisfied (if | 207 // - |MOJO_RESULT_ALREADY_EXISTS| if |signals| is already satisfied (if |
| 202 // |force| is true, the awakable will still be added); | 208 // |force| is true, the awakable will still be added); |
| 203 // - |MOJO_RESULT_INVALID_ARGUMENT| if the dispatcher has been closed; and | 209 // - |MOJO_RESULT_INVALID_ARGUMENT| if the dispatcher has been closed; and |
| 204 // - |MOJO_RESULT_FAILED_PRECONDITION| if it is not (or no longer) possible | 210 // - |MOJO_RESULT_FAILED_PRECONDITION| if it is not (or no longer) possible |
| 205 // that |signals| will ever be satisfied. | 211 // that |signals| will ever be satisfied. |
| 206 MojoResult AddAwakable(Awakable* awakable, | 212 MojoResult AddAwakable(Awakable* awakable, |
| 207 MojoHandleSignals signals, | 213 MojoHandleSignals signals, |
| 208 uint64_t context, | 214 uint64_t context, |
| 209 HandleSignalsState* signals_state); | 215 HandleSignalsState* signals_state); |
| 210 // Like |AddAwakable()|, but in the |MOJO_RESULT_ALREADY_EXISTS| case still | 216 // Like |AddAwakable()|, but in the |MOJO_RESULT_ALREADY_EXISTS| case still |
| 211 // adds the awakable (|MOJO_RESULT_ALREADY_EXISTS| will still be returned and | 217 // adds the awakable (|MOJO_RESULT_ALREADY_EXISTS| will still be returned and |
| 212 // |*signals_state| will still be set if |signals_state| is non-null). | 218 // |*signals_state| will still be set if |signals_state| is non-null). |
| 213 MojoResult AddAwakableUnconditional(Awakable* awakable, | 219 MojoResult AddAwakableUnconditional(Awakable* awakable, |
| 214 MojoHandleSignals signals, | 220 MojoHandleSignals signals, |
| 215 uint64_t context, | 221 uint64_t context, |
| 216 HandleSignalsState* signals_state); | 222 HandleSignalsState* signals_state); |
| 217 // Removes an awakable from this dispatcher. (It is valid to call this | 223 // Removes an awakable from this dispatcher. This will remove all instances of |
| 218 // multiple times for the same |awakable| on the same object, so long as | 224 // |awakable|, regardless of context. (It is valid to call this multiple times |
| 219 // |AddAwakable()| was called at most once.) If |signals_state| is non-null, | 225 // for the same |awakable| on the same object.) If |signals_state| is |
| 220 // |*signals_state| will be set to the current handle signals state. | 226 // non-null, |*signals_state| will be set to the current handle signals state. |
| 221 void RemoveAwakable(Awakable* awakable, HandleSignalsState* signals_state); | 227 void RemoveAwakable(Awakable* awakable, HandleSignalsState* signals_state); |
| 228 // Like |RemoveAwakable()|, but only removes "instances" with the given |
| 229 // context. (This may also be called multiple times, and there may be multiple |
| 230 // instances with the same context.) |
| 231 void RemoveAwakableWithContext(Awakable* awakable, |
| 232 uint64_t context, |
| 233 HandleSignalsState* signals_state); |
| 222 | 234 |
| 223 // A dispatcher must be put into a special state in order to be sent across a | 235 // A dispatcher must be put into a special state in order to be sent across a |
| 224 // message pipe. Outside of tests, only |HandleTableAccess| is allowed to do | 236 // message pipe. Outside of tests, only |HandleTableAccess| is allowed to do |
| 225 // this, since there are requirements on the handle table (see below). | 237 // this, since there are requirements on the handle table (see below). |
| 226 // | 238 // |
| 227 // In this special state, only a restricted set of operations is allowed. | 239 // In this special state, only a restricted set of operations is allowed. |
| 228 // These are the ones available as |HandleTransport| methods. Other | 240 // These are the ones available as |HandleTransport| methods. Other |
| 229 // |Dispatcher| methods must not be called until |HandleTransport::End()| has | 241 // |Dispatcher| methods must not be called until |HandleTransport::End()| has |
| 230 // been called. | 242 // been called. |
| 231 class HandleTableAccess { | 243 class HandleTableAccess { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 MOJO_SHARED_LOCKS_REQUIRED(mutex_); | 402 MOJO_SHARED_LOCKS_REQUIRED(mutex_); |
| 391 virtual MojoResult AddAwakableImplNoLock(Awakable* awakable, | 403 virtual MojoResult AddAwakableImplNoLock(Awakable* awakable, |
| 392 MojoHandleSignals signals, | 404 MojoHandleSignals signals, |
| 393 bool force, | 405 bool force, |
| 394 uint64_t context, | 406 uint64_t context, |
| 395 HandleSignalsState* signals_state) | 407 HandleSignalsState* signals_state) |
| 396 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 408 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
| 397 virtual void RemoveAwakableImplNoLock(Awakable* awakable, | 409 virtual void RemoveAwakableImplNoLock(Awakable* awakable, |
| 398 HandleSignalsState* signals_state) | 410 HandleSignalsState* signals_state) |
| 399 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 411 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
| 412 virtual void RemoveAwakableWithContextImplNoLock( |
| 413 Awakable* awakable, |
| 414 uint64_t context, |
| 415 HandleSignalsState* signals_state) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
| 400 | 416 |
| 401 // These implement the API used to serialize dispatchers to a |Channel| | 417 // These implement the API used to serialize dispatchers to a |Channel| |
| 402 // (described below). They will only be called on a dispatcher that's attached | 418 // (described below). They will only be called on a dispatcher that's attached |
| 403 // to and "owned" by a |MessageInTransit|. See the non-"impl" versions for | 419 // to and "owned" by a |MessageInTransit|. See the non-"impl" versions for |
| 404 // more information. | 420 // more information. |
| 405 // | 421 // |
| 406 // Note: |StartSerializeImplNoLock()| is actually called with |mutex_| NOT | 422 // Note: |StartSerializeImplNoLock()| is actually called with |mutex_| NOT |
| 407 // held, since the dispatcher should only be accessible to the calling thread. | 423 // held, since the dispatcher should only be accessible to the calling thread. |
| 408 // On Debug builds, |EndSerializeAndCloseImplNoLock()| is called with |mutex_| | 424 // On Debug builds, |EndSerializeAndCloseImplNoLock()| is called with |mutex_| |
| 409 // held, to satisfy any |mutex_.AssertHeld()| (e.g., in |CloseImplNoLock()| -- | 425 // held, to satisfy any |mutex_.AssertHeld()| (e.g., in |CloseImplNoLock()| -- |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 518 |
| 503 // So logging macros and |DCHECK_EQ()|, etc. work. | 519 // So logging macros and |DCHECK_EQ()|, etc. work. |
| 504 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { | 520 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { |
| 505 return out << static_cast<int>(type); | 521 return out << static_cast<int>(type); |
| 506 } | 522 } |
| 507 | 523 |
| 508 } // namespace system | 524 } // namespace system |
| 509 } // namespace mojo | 525 } // namespace mojo |
| 510 | 526 |
| 511 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ | 527 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ |
| OLD | NEW |