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

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

Issue 2052423002: Add Dispatcher methods for wait sets. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: oops 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/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
11 #include <memory> 11 #include <memory>
12 #include <ostream> 12 #include <ostream>
13 #include <vector> 13 #include <vector>
14 14
15 #include "mojo/edk/platform/scoped_platform_handle.h" 15 #include "mojo/edk/platform/scoped_platform_handle.h"
16 #include "mojo/edk/system/entrypoint_class.h" 16 #include "mojo/edk/system/entrypoint_class.h"
17 #include "mojo/edk/system/handle.h" 17 #include "mojo/edk/system/handle.h"
18 #include "mojo/edk/system/handle_signals_state.h" 18 #include "mojo/edk/system/handle_signals_state.h"
19 #include "mojo/edk/system/memory.h" 19 #include "mojo/edk/system/memory.h"
20 #include "mojo/edk/util/mutex.h" 20 #include "mojo/edk/util/mutex.h"
21 #include "mojo/edk/util/ref_counted.h" 21 #include "mojo/edk/util/ref_counted.h"
22 #include "mojo/edk/util/ref_ptr.h" 22 #include "mojo/edk/util/ref_ptr.h"
23 #include "mojo/edk/util/thread_annotations.h" 23 #include "mojo/edk/util/thread_annotations.h"
24 #include "mojo/public/c/system/buffer.h" 24 #include "mojo/public/c/system/buffer.h"
25 #include "mojo/public/c/system/data_pipe.h" 25 #include "mojo/public/c/system/data_pipe.h"
26 #include "mojo/public/c/system/handle.h" 26 #include "mojo/public/c/system/handle.h"
27 #include "mojo/public/c/system/message_pipe.h" 27 #include "mojo/public/c/system/message_pipe.h"
28 #include "mojo/public/c/system/result.h" 28 #include "mojo/public/c/system/result.h"
29 #include "mojo/public/c/system/wait_set.h"
29 #include "mojo/public/cpp/system/macros.h" 30 #include "mojo/public/cpp/system/macros.h"
30 31
31 namespace mojo { 32 namespace mojo {
32 33
33 namespace platform { 34 namespace platform {
34 class PlatformSharedBufferMapping; 35 class PlatformSharedBufferMapping;
35 } 36 }
36 37
37 namespace system { 38 namespace system {
38 39
(...skipping 27 matching lines...) Expand all
66 public: 67 public:
67 // Types of dispatchers. Note that these are not necessarily a one-to-one with 68 // Types of dispatchers. Note that these are not necessarily a one-to-one with
68 // implementations of |Dispatcher|: multiple implementations may share the 69 // implementations of |Dispatcher|: multiple implementations may share the
69 // same type. 70 // same type.
70 enum class Type { 71 enum class Type {
71 UNKNOWN = 0, 72 UNKNOWN = 0,
72 MESSAGE_PIPE, 73 MESSAGE_PIPE,
73 DATA_PIPE_PRODUCER, 74 DATA_PIPE_PRODUCER,
74 DATA_PIPE_CONSUMER, 75 DATA_PIPE_CONSUMER,
75 SHARED_BUFFER, 76 SHARED_BUFFER,
77 WAIT_SET,
76 78
77 // "Private" types (not exposed via the public interface): 79 // "Private" types (not exposed via the public interface):
78 PLATFORM_HANDLE = -1 80 PLATFORM_HANDLE = -1
79 }; 81 };
80 82
81 // Gets the type of the dispatcher; see |Type| above. 83 // Gets the type of the dispatcher; see |Type| above.
82 virtual Type GetType() const = 0; 84 virtual Type GetType() const = 0;
83 85
84 // Gets whether the given entrypoint class is supported; see the definition of 86 // Gets whether the given entrypoint class is supported; see the definition of
85 // |EntrypointClass|. This is ONLY called when a rights check has failed, to 87 // |EntrypointClass|. This is ONLY called when a rights check has failed, to
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 UserPointer<const MojoDuplicateBufferHandleOptions> options, 162 UserPointer<const MojoDuplicateBufferHandleOptions> options,
161 util::RefPtr<Dispatcher>* new_dispatcher); 163 util::RefPtr<Dispatcher>* new_dispatcher);
162 MojoResult GetBufferInformation(UserPointer<MojoBufferInformation> info, 164 MojoResult GetBufferInformation(UserPointer<MojoBufferInformation> info,
163 uint32_t info_num_bytes); 165 uint32_t info_num_bytes);
164 MojoResult MapBuffer( 166 MojoResult MapBuffer(
165 uint64_t offset, 167 uint64_t offset,
166 uint64_t num_bytes, 168 uint64_t num_bytes,
167 MojoMapBufferFlags flags, 169 MojoMapBufferFlags flags,
168 std::unique_ptr<platform::PlatformSharedBufferMapping>* mapping); 170 std::unique_ptr<platform::PlatformSharedBufferMapping>* mapping);
169 171
172 // |EntrypointClass::WAIT_SET|:
173 MojoResult WaitSetAdd(UserPointer<const MojoWaitSetAddOptions> options,
174 Handle&& handle,
175 MojoHandleSignals signals,
176 uint64_t cookie);
177 MojoResult WaitSetRemove(uint64_t cookie);
178 // Note: This will likely block the calling thread (so, e.g., no mutexes
179 // should be held when it's called).
180 MojoResult WaitSetWait(MojoDeadline deadline,
181 UserPointer<uint32_t> num_results,
182 UserPointer<MojoWaitSetResult> results,
183 UserPointer<uint32_t> max_results);
184
170 // Gets the current handle signals state. (The default implementation simply 185 // Gets the current handle signals state. (The default implementation simply
171 // returns a default-constructed |HandleSignalsState|, i.e., no signals 186 // returns a default-constructed |HandleSignalsState|, i.e., no signals
172 // 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
173 // threads. 188 // threads.
174 HandleSignalsState GetHandleSignalsState() const; 189 HandleSignalsState GetHandleSignalsState() const;
175 190
176 // 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
177 // object changes state to satisfy |signals| with context |context|. It will 192 // object changes state to satisfy |signals| with context |context|. It will
178 // 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
179 // |signals| with a suitable error status. 194 // |signals| with a suitable error status.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 virtual MojoResult WriteDataImplNoLock(UserPointer<const void> elements, 328 virtual MojoResult WriteDataImplNoLock(UserPointer<const void> elements,
314 UserPointer<uint32_t> num_bytes, 329 UserPointer<uint32_t> num_bytes,
315 MojoWriteDataFlags flags) 330 MojoWriteDataFlags flags)
316 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 331 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
317 virtual MojoResult BeginWriteDataImplNoLock( 332 virtual MojoResult BeginWriteDataImplNoLock(
318 UserPointer<void*> buffer, 333 UserPointer<void*> buffer,
319 UserPointer<uint32_t> buffer_num_bytes, 334 UserPointer<uint32_t> buffer_num_bytes,
320 MojoWriteDataFlags flags) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 335 MojoWriteDataFlags flags) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
321 virtual MojoResult EndWriteDataImplNoLock(uint32_t num_bytes_written) 336 virtual MojoResult EndWriteDataImplNoLock(uint32_t num_bytes_written)
322 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 337 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
323 virtual MojoResult ReadDataImplNoLock(UserPointer<void> elements,
324 UserPointer<uint32_t> num_bytes,
325 MojoReadDataFlags flags)
326 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
327 virtual MojoResult SetDataPipeConsumerOptionsImplNoLock( 338 virtual MojoResult SetDataPipeConsumerOptionsImplNoLock(
328 UserPointer<const MojoDataPipeConsumerOptions> options) 339 UserPointer<const MojoDataPipeConsumerOptions> options)
329 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 340 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
330 virtual MojoResult GetDataPipeConsumerOptionsImplNoLock( 341 virtual MojoResult GetDataPipeConsumerOptionsImplNoLock(
331 UserPointer<MojoDataPipeConsumerOptions> options, 342 UserPointer<MojoDataPipeConsumerOptions> options,
332 uint32_t options_num_bytes) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 343 uint32_t options_num_bytes) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
344 virtual MojoResult ReadDataImplNoLock(UserPointer<void> elements,
345 UserPointer<uint32_t> num_bytes,
346 MojoReadDataFlags flags)
347 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
333 virtual MojoResult BeginReadDataImplNoLock( 348 virtual MojoResult BeginReadDataImplNoLock(
334 UserPointer<const void*> buffer, 349 UserPointer<const void*> buffer,
335 UserPointer<uint32_t> buffer_num_bytes, 350 UserPointer<uint32_t> buffer_num_bytes,
336 MojoReadDataFlags flags) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 351 MojoReadDataFlags flags) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
337 virtual MojoResult EndReadDataImplNoLock(uint32_t num_bytes_read) 352 virtual MojoResult EndReadDataImplNoLock(uint32_t num_bytes_read)
338 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 353 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
339 virtual MojoResult DuplicateBufferHandleImplNoLock( 354 virtual MojoResult DuplicateBufferHandleImplNoLock(
340 UserPointer<const MojoDuplicateBufferHandleOptions> options, 355 UserPointer<const MojoDuplicateBufferHandleOptions> options,
341 util::RefPtr<Dispatcher>* new_dispatcher) 356 util::RefPtr<Dispatcher>* new_dispatcher)
342 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 357 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
343 virtual MojoResult GetBufferInformationImplNoLock( 358 virtual MojoResult GetBufferInformationImplNoLock(
344 UserPointer<MojoBufferInformation> info, 359 UserPointer<MojoBufferInformation> info,
345 uint32_t info_num_bytes) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 360 uint32_t info_num_bytes) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
346 virtual MojoResult MapBufferImplNoLock( 361 virtual MojoResult MapBufferImplNoLock(
347 uint64_t offset, 362 uint64_t offset,
348 uint64_t num_bytes, 363 uint64_t num_bytes,
349 MojoMapBufferFlags flags, 364 MojoMapBufferFlags flags,
350 std::unique_ptr<platform::PlatformSharedBufferMapping>* mapping) 365 std::unique_ptr<platform::PlatformSharedBufferMapping>* mapping)
351 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 366 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
367 virtual MojoResult WaitSetAddImplNoLock(
368 UserPointer<const MojoWaitSetAddOptions> options,
369 Handle&& handle,
370 MojoHandleSignals signals,
371 uint64_t cookie) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
372 virtual MojoResult WaitSetRemoveImplNoLock(uint64_t cookie)
373 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
374 // WARNING: Unlike the others, this method is *not* called under |mutex_| and
375 // |is_closed_| is *not* checked. Thus any override must lock |mutex()| and
376 // check |is_closed_no_lock()| (returning |MOJO_RESULT_INVALID_ARGUMENT| if it
377 // is true).
378 virtual MojoResult WaitSetWaitImpl(MojoDeadline deadline,
379 UserPointer<uint32_t> num_results,
380 UserPointer<MojoWaitSetResult> results,
381 UserPointer<uint32_t> max_results);
352 virtual HandleSignalsState GetHandleSignalsStateImplNoLock() const 382 virtual HandleSignalsState GetHandleSignalsStateImplNoLock() const
353 MOJO_SHARED_LOCKS_REQUIRED(mutex_); 383 MOJO_SHARED_LOCKS_REQUIRED(mutex_);
354 virtual MojoResult AddAwakableImplNoLock(Awakable* awakable, 384 virtual MojoResult AddAwakableImplNoLock(Awakable* awakable,
355 MojoHandleSignals signals, 385 MojoHandleSignals signals,
356 uint64_t context, 386 uint64_t context,
357 HandleSignalsState* signals_state) 387 HandleSignalsState* signals_state)
358 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 388 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
359 virtual void RemoveAwakableImplNoLock(Awakable* awakable, 389 virtual void RemoveAwakableImplNoLock(Awakable* awakable,
360 HandleSignalsState* signals_state) 390 HandleSignalsState* signals_state)
361 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 391 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
(...skipping 18 matching lines...) Expand all
380 MOJO_NOT_THREAD_SAFE; 410 MOJO_NOT_THREAD_SAFE;
381 virtual bool EndSerializeAndCloseImplNoLock( 411 virtual bool EndSerializeAndCloseImplNoLock(
382 Channel* channel, 412 Channel* channel,
383 void* destination, 413 void* destination,
384 size_t* actual_size, 414 size_t* actual_size,
385 std::vector<platform::ScopedPlatformHandle>* platform_handles) 415 std::vector<platform::ScopedPlatformHandle>* platform_handles)
386 MOJO_NOT_THREAD_SAFE; 416 MOJO_NOT_THREAD_SAFE;
387 417
388 util::Mutex& mutex() const MOJO_LOCK_RETURNED(mutex_) { return mutex_; } 418 util::Mutex& mutex() const MOJO_LOCK_RETURNED(mutex_) { return mutex_; }
389 419
420 bool is_closed_no_lock() const MOJO_SHARED_LOCKS_REQUIRED(mutex_) {
421 return is_closed_;
422 }
423
390 private: 424 private:
391 FRIEND_REF_COUNTED_THREAD_SAFE(Dispatcher); 425 FRIEND_REF_COUNTED_THREAD_SAFE(Dispatcher);
392 friend class HandleTransport; 426 friend class HandleTransport;
393 427
394 // Closes the dispatcher. This must be done under lock, and unlike |Close()|, 428 // Closes the dispatcher. This must be done under lock, and unlike |Close()|,
395 // the dispatcher must not be closed already. (This is the "equivalent" of 429 // the dispatcher must not be closed already. (This is the "equivalent" of
396 // |CreateEquivalentDispatcherAndCloseNoLock()|, for situations where the 430 // |CreateEquivalentDispatcherAndCloseNoLock()|, for situations where the
397 // dispatcher must be disposed of instead of "transferred".) 431 // dispatcher must be disposed of instead of "transferred".)
398 void CloseNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 432 void CloseNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
399 433
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 494
461 // So logging macros and |DCHECK_EQ()|, etc. work. 495 // So logging macros and |DCHECK_EQ()|, etc. work.
462 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { 496 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) {
463 return out << static_cast<int>(type); 497 return out << static_cast<int>(type);
464 } 498 }
465 499
466 } // namespace system 500 } // namespace system
467 } // namespace mojo 501 } // namespace mojo
468 502
469 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ 503 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/system/dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698