| 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 #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" |
| 11 #include "mojo/edk/system/handle_transport.h" |
| 11 #include "mojo/edk/system/message_pipe_dispatcher.h" | 12 #include "mojo/edk/system/message_pipe_dispatcher.h" |
| 12 #include "mojo/edk/system/platform_handle_dispatcher.h" | 13 #include "mojo/edk/system/platform_handle_dispatcher.h" |
| 13 #include "mojo/edk/system/shared_buffer_dispatcher.h" | 14 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
| 14 | 15 |
| 15 using mojo::platform::PlatformSharedBufferMapping; | 16 using mojo::platform::PlatformSharedBufferMapping; |
| 16 using mojo::platform::ScopedPlatformHandle; | 17 using mojo::platform::ScopedPlatformHandle; |
| 17 using mojo::util::MutexLocker; | 18 using mojo::util::MutexLocker; |
| 18 using mojo::util::RefPtr; | 19 using mojo::util::RefPtr; |
| 19 | 20 |
| 20 namespace mojo { | 21 namespace mojo { |
| 21 namespace system { | 22 namespace system { |
| 22 | 23 |
| 23 namespace test { | 24 namespace test { |
| 24 | 25 |
| 25 // TODO(vtl): Maybe this should be defined in a test-only file instead. | 26 // TODO(vtl): Maybe this should be defined in a test-only file instead. |
| 26 DispatcherTransport DispatcherTryStartTransport(Dispatcher* dispatcher) { | 27 DispatcherTransport DispatcherTryStartTransport(Dispatcher* dispatcher) { |
| 27 return Dispatcher::HandleTableAccess::TryStartTransport(dispatcher); | 28 return Dispatcher::HandleTableAccess::TryStartTransport(dispatcher); |
| 28 } | 29 } |
| 29 | 30 |
| 30 } // namespace test | 31 } // namespace test |
| 31 | 32 |
| 32 // Dispatcher ------------------------------------------------------------------ | |
| 33 | |
| 34 // TODO(vtl): The thread-safety analyzer isn't smart enough to deal with the | 33 // TODO(vtl): The thread-safety analyzer isn't smart enough to deal with the |
| 35 // fact that we give up if |TryLock()| fails. | 34 // fact that we give up if |TryLock()| fails. |
| 36 // static | 35 // static |
| 37 DispatcherTransport Dispatcher::HandleTableAccess::TryStartTransport( | 36 DispatcherTransport Dispatcher::HandleTableAccess::TryStartTransport( |
| 38 Dispatcher* dispatcher) MOJO_NO_THREAD_SAFETY_ANALYSIS { | 37 Dispatcher* dispatcher) MOJO_NO_THREAD_SAFETY_ANALYSIS { |
| 39 DCHECK(dispatcher); | 38 DCHECK(dispatcher); |
| 40 | 39 |
| 41 if (!dispatcher->mutex_.TryLock()) | 40 if (!dispatcher->mutex_.TryLock()) |
| 42 return DispatcherTransport(); | 41 return DispatcherTransport(); |
| 43 | 42 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 MutexLocker locker(&mutex_); | 292 MutexLocker locker(&mutex_); |
| 294 if (is_closed_) { | 293 if (is_closed_) { |
| 295 if (handle_signals_state) | 294 if (handle_signals_state) |
| 296 *handle_signals_state = HandleSignalsState(); | 295 *handle_signals_state = HandleSignalsState(); |
| 297 return; | 296 return; |
| 298 } | 297 } |
| 299 | 298 |
| 300 RemoveAwakableImplNoLock(awakable, handle_signals_state); | 299 RemoveAwakableImplNoLock(awakable, handle_signals_state); |
| 301 } | 300 } |
| 302 | 301 |
| 303 Dispatcher::Dispatcher() : is_closed_(false) { | 302 Dispatcher::Dispatcher() : is_closed_(false) {} |
| 304 } | |
| 305 | 303 |
| 306 Dispatcher::~Dispatcher() { | 304 Dispatcher::~Dispatcher() { |
| 307 // Make sure that |Close()| was called. | 305 // Make sure that |Close()| was called. |
| 308 DCHECK(is_closed_); | 306 DCHECK(is_closed_); |
| 309 } | 307 } |
| 310 | 308 |
| 311 void Dispatcher::CancelAllAwakablesNoLock() { | 309 void Dispatcher::CancelAllAwakablesNoLock() { |
| 312 mutex_.AssertHeld(); | 310 mutex_.AssertHeld(); |
| 313 DCHECK(is_closed_); | 311 DCHECK(is_closed_); |
| 314 // By default, waiting isn't supported. Only dispatchers that can be waited on | 312 // By default, waiting isn't supported. Only dispatchers that can be waited on |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 // See the comment above |EndSerializeAndCloseImplNoLock()|. In brief: Locking | 564 // See the comment above |EndSerializeAndCloseImplNoLock()|. In brief: Locking |
| 567 // isn't actually needed, but we need to satisfy assertions (which we don't | 565 // isn't actually needed, but we need to satisfy assertions (which we don't |
| 568 // want to remove or weaken). | 566 // want to remove or weaken). |
| 569 MutexLocker locker(&mutex_); | 567 MutexLocker locker(&mutex_); |
| 570 #endif | 568 #endif |
| 571 | 569 |
| 572 return EndSerializeAndCloseImplNoLock(channel, destination, actual_size, | 570 return EndSerializeAndCloseImplNoLock(channel, destination, actual_size, |
| 573 platform_handles); | 571 platform_handles); |
| 574 } | 572 } |
| 575 | 573 |
| 576 // DispatcherTransport --------------------------------------------------------- | |
| 577 | |
| 578 void DispatcherTransport::End() { | |
| 579 DCHECK(dispatcher_); | |
| 580 dispatcher_->mutex_.Unlock(); | |
| 581 dispatcher_ = nullptr; | |
| 582 } | |
| 583 | |
| 584 } // namespace system | 574 } // namespace system |
| 585 } // namespace mojo | 575 } // namespace mojo |
| OLD | NEW |