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

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

Issue 1504733002: Implementation of WaitSet for new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-waitset-implementation
Patch Set: Add gyp rules. Created 5 years 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/dispatcher.h ('k') | mojo/edk/system/wait_set_dispatcher.h » ('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 #include "mojo/edk/system/dispatcher.h" 5 #include "mojo/edk/system/dispatcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "mojo/edk/system/configuration.h" 8 #include "mojo/edk/system/configuration.h"
9 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" 9 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h"
10 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" 10 #include "mojo/edk/system/data_pipe_producer_dispatcher.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 69 }
70 70
71 // static 71 // static
72 scoped_refptr<Dispatcher> Dispatcher::TransportDataAccess::Deserialize( 72 scoped_refptr<Dispatcher> Dispatcher::TransportDataAccess::Deserialize(
73 int32_t type, 73 int32_t type,
74 const void* source, 74 const void* source,
75 size_t size, 75 size_t size,
76 PlatformHandleVector* platform_handles) { 76 PlatformHandleVector* platform_handles) {
77 switch (static_cast<Dispatcher::Type>(type)) { 77 switch (static_cast<Dispatcher::Type>(type)) {
78 case Type::UNKNOWN: 78 case Type::UNKNOWN:
79 case Type::WAIT_SET:
79 DVLOG(2) << "Deserializing invalid handle"; 80 DVLOG(2) << "Deserializing invalid handle";
80 return nullptr; 81 return nullptr;
81 case Type::MESSAGE_PIPE: 82 case Type::MESSAGE_PIPE:
82 return scoped_refptr<Dispatcher>(MessagePipeDispatcher::Deserialize( 83 return scoped_refptr<Dispatcher>(MessagePipeDispatcher::Deserialize(
83 source, size, platform_handles)); 84 source, size, platform_handles));
84 case Type::DATA_PIPE_PRODUCER: 85 case Type::DATA_PIPE_PRODUCER:
85 return scoped_refptr<Dispatcher>( 86 return scoped_refptr<Dispatcher>(
86 DataPipeProducerDispatcher::Deserialize( 87 DataPipeProducerDispatcher::Deserialize(
87 source, size, platform_handles)); 88 source, size, platform_handles));
88 case Type::DATA_PIPE_CONSUMER: 89 case Type::DATA_PIPE_CONSUMER:
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 base::AutoLock locker(lock_); 247 base::AutoLock locker(lock_);
247 if (is_closed_) { 248 if (is_closed_) {
248 if (handle_signals_state) 249 if (handle_signals_state)
249 *handle_signals_state = HandleSignalsState(); 250 *handle_signals_state = HandleSignalsState();
250 return; 251 return;
251 } 252 }
252 253
253 RemoveAwakableImplNoLock(awakable, handle_signals_state); 254 RemoveAwakableImplNoLock(awakable, handle_signals_state);
254 } 255 }
255 256
257 MojoResult Dispatcher::AddWaitingDispatcher(
258 const scoped_refptr<Dispatcher>& dispatcher,
259 MojoHandleSignals signals,
260 uintptr_t context) {
261 base::AutoLock locker(lock_);
262 if (is_closed_)
263 return MOJO_RESULT_INVALID_ARGUMENT;
264
265 return AddWaitingDispatcherImplNoLock(dispatcher, signals, context);
266 }
267
268 MojoResult Dispatcher::RemoveWaitingDispatcher(
269 const scoped_refptr<Dispatcher>& dispatcher) {
270 base::AutoLock locker(lock_);
271 if (is_closed_)
272 return MOJO_RESULT_INVALID_ARGUMENT;
273
274 return RemoveWaitingDispatcherImplNoLock(dispatcher);
275 }
276
277 MojoResult Dispatcher::GetReadyDispatchers(uint32_t* count,
278 DispatcherVector* dispatchers,
279 MojoResult* results,
280 uintptr_t* contexts) {
281 base::AutoLock locker(lock_);
282 if (is_closed_)
283 return MOJO_RESULT_INVALID_ARGUMENT;
284
285 return GetReadyDispatchersImplNoLock(count, dispatchers, results, contexts);
286 }
287
256 Dispatcher::Dispatcher() : is_closed_(false) { 288 Dispatcher::Dispatcher() : is_closed_(false) {
257 } 289 }
258 290
259 Dispatcher::~Dispatcher() { 291 Dispatcher::~Dispatcher() {
260 // Make sure that |Close()| was called. 292 // Make sure that |Close()| was called.
261 DCHECK(is_closed_); 293 DCHECK(is_closed_);
262 } 294 }
263 295
264 void Dispatcher::CancelAllAwakablesNoLock() { 296 void Dispatcher::CancelAllAwakablesNoLock() {
265 lock_.AssertAcquired(); 297 lock_.AssertAcquired();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 HandleSignalsState* signals_state) { 417 HandleSignalsState* signals_state) {
386 lock_.AssertAcquired(); 418 lock_.AssertAcquired();
387 DCHECK(!is_closed_); 419 DCHECK(!is_closed_);
388 // By default, waiting isn't supported. Only dispatchers that can be waited on 420 // By default, waiting isn't supported. Only dispatchers that can be waited on
389 // will do something nontrivial. 421 // will do something nontrivial.
390 if (signals_state) 422 if (signals_state)
391 *signals_state = HandleSignalsState(); 423 *signals_state = HandleSignalsState();
392 return MOJO_RESULT_FAILED_PRECONDITION; 424 return MOJO_RESULT_FAILED_PRECONDITION;
393 } 425 }
394 426
427 MojoResult Dispatcher::AddWaitingDispatcherImplNoLock(
428 const scoped_refptr<Dispatcher>& /*dispatcher*/,
429 MojoHandleSignals /*signals*/,
430 uintptr_t /*context*/) {
431 lock_.AssertAcquired();
432 DCHECK(!is_closed_);
433 // By default, not supported. Only needed for wait set dispatchers.
434 return MOJO_RESULT_INVALID_ARGUMENT;
435 }
436
437 MojoResult Dispatcher::RemoveWaitingDispatcherImplNoLock(
438 const scoped_refptr<Dispatcher>& /*dispatcher*/) {
439 lock_.AssertAcquired();
440 DCHECK(!is_closed_);
441 // By default, not supported. Only needed for wait set dispatchers.
442 return MOJO_RESULT_INVALID_ARGUMENT;
443 }
444
445 MojoResult Dispatcher::GetReadyDispatchersImplNoLock(
446 uint32_t* /*count*/,
447 DispatcherVector* /*dispatchers*/,
448 MojoResult* /*results*/,
449 uintptr_t* /*contexts*/) {
450 lock_.AssertAcquired();
451 DCHECK(!is_closed_);
452 // By default, not supported. Only needed for wait set dispatchers.
453 return MOJO_RESULT_INVALID_ARGUMENT;
454 }
455
395 void Dispatcher::RemoveAwakableImplNoLock(Awakable* /*awakable*/, 456 void Dispatcher::RemoveAwakableImplNoLock(Awakable* /*awakable*/,
396 HandleSignalsState* signals_state) { 457 HandleSignalsState* signals_state) {
397 lock_.AssertAcquired(); 458 lock_.AssertAcquired();
398 DCHECK(!is_closed_); 459 DCHECK(!is_closed_);
399 // By default, waiting isn't supported. Only dispatchers that can be waited on 460 // By default, waiting isn't supported. Only dispatchers that can be waited on
400 // will do something nontrivial. 461 // will do something nontrivial.
401 if (signals_state) 462 if (signals_state)
402 *signals_state = HandleSignalsState(); 463 *signals_state = HandleSignalsState();
403 } 464 }
404 465
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 DCHECK(dispatcher_); 538 DCHECK(dispatcher_);
478 dispatcher_->lock_.Release(); 539 dispatcher_->lock_.Release();
479 540
480 dispatcher_->TransportEnded(); 541 dispatcher_->TransportEnded();
481 542
482 dispatcher_ = nullptr; 543 dispatcher_ = nullptr;
483 } 544 }
484 545
485 } // namespace edk 546 } // namespace edk
486 } // namespace mojo 547 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/dispatcher.h ('k') | mojo/edk/system/wait_set_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698