| 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" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 MojoResult Dispatcher::Close() { | 106 MojoResult Dispatcher::Close() { |
| 107 MutexLocker locker(&mutex_); | 107 MutexLocker locker(&mutex_); |
| 108 if (is_closed_) | 108 if (is_closed_) |
| 109 return MOJO_RESULT_INVALID_ARGUMENT; | 109 return MOJO_RESULT_INVALID_ARGUMENT; |
| 110 | 110 |
| 111 CloseNoLock(); | 111 CloseNoLock(); |
| 112 return MOJO_RESULT_OK; | 112 return MOJO_RESULT_OK; |
| 113 } | 113 } |
| 114 | 114 |
| 115 MojoResult Dispatcher::DuplicateDispatcher( | 115 MojoResult Dispatcher::DuplicateDispatcher(RefPtr<Dispatcher>* new_dispatcher) { |
| 116 util::RefPtr<Dispatcher>* new_dispatcher) { | |
| 117 MutexLocker locker(&mutex_); | 116 MutexLocker locker(&mutex_); |
| 118 if (is_closed_) | 117 if (is_closed_) |
| 119 return MOJO_RESULT_INVALID_ARGUMENT; | 118 return MOJO_RESULT_INVALID_ARGUMENT; |
| 120 | 119 |
| 121 return DuplicateDispatcherImplNoLock(new_dispatcher); | 120 return DuplicateDispatcherImplNoLock(new_dispatcher); |
| 122 } | 121 } |
| 123 | 122 |
| 124 MojoResult Dispatcher::WriteMessage(UserPointer<const void> bytes, | 123 MojoResult Dispatcher::WriteMessage(UserPointer<const void> bytes, |
| 125 uint32_t num_bytes, | 124 uint32_t num_bytes, |
| 126 std::vector<HandleTransport>* transports, | 125 std::vector<HandleTransport>* transports, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 return MOJO_RESULT_INVALID_ARGUMENT; | 273 return MOJO_RESULT_INVALID_ARGUMENT; |
| 275 | 274 |
| 276 return MapBufferImplNoLock(offset, num_bytes, flags, mapping); | 275 return MapBufferImplNoLock(offset, num_bytes, flags, mapping); |
| 277 } | 276 } |
| 278 | 277 |
| 279 // Note: The following three wait set methods don't lock |mutex_|, and leave | 278 // Note: The following three wait set methods don't lock |mutex_|, and leave |
| 280 // everything for |WaitSet...Impl()| to do. (We could just make these methods | 279 // everything for |WaitSet...Impl()| to do. (We could just make these methods |
| 281 // virtual, but we prefer to have a separate "impl" methods for consistency.) | 280 // virtual, but we prefer to have a separate "impl" methods for consistency.) |
| 282 MojoResult Dispatcher::WaitSetAdd( | 281 MojoResult Dispatcher::WaitSetAdd( |
| 283 UserPointer<const MojoWaitSetAddOptions> options, | 282 UserPointer<const MojoWaitSetAddOptions> options, |
| 284 Handle&& handle, | 283 RefPtr<Dispatcher>&& dispatcher, |
| 285 MojoHandleSignals signals, | 284 MojoHandleSignals signals, |
| 286 uint64_t cookie) { | 285 uint64_t cookie) { |
| 287 return WaitSetAddImpl(options, std::move(handle), signals, cookie); | 286 return WaitSetAddImpl(options, std::move(dispatcher), signals, cookie); |
| 288 } | 287 } |
| 289 | 288 |
| 290 MojoResult Dispatcher::WaitSetRemove(uint64_t cookie) { | 289 MojoResult Dispatcher::WaitSetRemove(uint64_t cookie) { |
| 291 return WaitSetRemoveImpl(cookie); | 290 return WaitSetRemoveImpl(cookie); |
| 292 } | 291 } |
| 293 | 292 |
| 294 MojoResult Dispatcher::WaitSetWait(MojoDeadline deadline, | 293 MojoResult Dispatcher::WaitSetWait(MojoDeadline deadline, |
| 295 UserPointer<uint32_t> num_results, | 294 UserPointer<uint32_t> num_results, |
| 296 UserPointer<MojoWaitSetResult> results, | 295 UserPointer<MojoWaitSetResult> results, |
| 297 UserPointer<uint32_t> max_results) { | 296 UserPointer<uint32_t> max_results) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } | 375 } |
| 377 | 376 |
| 378 void Dispatcher::CloseImplNoLock() { | 377 void Dispatcher::CloseImplNoLock() { |
| 379 mutex_.AssertHeld(); | 378 mutex_.AssertHeld(); |
| 380 DCHECK(is_closed_); | 379 DCHECK(is_closed_); |
| 381 // This may not need to do anything. Dispatchers should override this to do | 380 // This may not need to do anything. Dispatchers should override this to do |
| 382 // any actual close-time cleanup necessary. | 381 // any actual close-time cleanup necessary. |
| 383 } | 382 } |
| 384 | 383 |
| 385 MojoResult Dispatcher::DuplicateDispatcherImplNoLock( | 384 MojoResult Dispatcher::DuplicateDispatcherImplNoLock( |
| 386 util::RefPtr<Dispatcher>* new_dispatcher) { | 385 RefPtr<Dispatcher>* new_dispatcher) { |
| 387 mutex_.AssertHeld(); | 386 mutex_.AssertHeld(); |
| 388 DCHECK(!is_closed_); | 387 DCHECK(!is_closed_); |
| 389 // By default, this is not supported. However, this should only be reachable | 388 // By default, this is not supported. However, this should only be reachable |
| 390 // if a handle has the |MOJO_HANDLE_RIGHT_DUPLICATE| right, which it should | 389 // if a handle has the |MOJO_HANDLE_RIGHT_DUPLICATE| right, which it should |
| 391 // only have if it is supported. | 390 // only have if it is supported. |
| 392 NOTREACHED(); | 391 NOTREACHED(); |
| 393 return MOJO_RESULT_INTERNAL; | 392 return MOJO_RESULT_INTERNAL; |
| 394 } | 393 } |
| 395 | 394 |
| 396 MojoResult Dispatcher::WriteMessageImplNoLock( | 395 MojoResult Dispatcher::WriteMessageImplNoLock( |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 return MOJO_RESULT_INVALID_ARGUMENT; | 530 return MOJO_RESULT_INVALID_ARGUMENT; |
| 532 } | 531 } |
| 533 | 532 |
| 534 // Note that the following three methods are *not* called under |mutex_| and | 533 // Note that the following three methods are *not* called under |mutex_| and |
| 535 // |is_closed_| hasn't been checked. However, since we'll return | 534 // |is_closed_| hasn't been checked. However, since we'll return |
| 536 // |MOJO_RESULT_INVALID_ARGUMENT| regardless of the value of |is_closed_| (these | 535 // |MOJO_RESULT_INVALID_ARGUMENT| regardless of the value of |is_closed_| (these |
| 537 // methods are only needed for wait set dispatchers), we don't need to lock | 536 // methods are only needed for wait set dispatchers), we don't need to lock |
| 538 // |mutex_| and check |is_closed_|. | 537 // |mutex_| and check |is_closed_|. |
| 539 MojoResult Dispatcher::WaitSetAddImpl( | 538 MojoResult Dispatcher::WaitSetAddImpl( |
| 540 UserPointer<const MojoWaitSetAddOptions> /*options*/, | 539 UserPointer<const MojoWaitSetAddOptions> /*options*/, |
| 541 Handle&& /*handle*/, | 540 RefPtr<Dispatcher>&& /*dispatcher*/, |
| 542 MojoHandleSignals /*signals*/, | 541 MojoHandleSignals /*signals*/, |
| 543 uint64_t /*cookie*/) { | 542 uint64_t /*cookie*/) { |
| 544 // See note above. | 543 // See note above. |
| 545 return MOJO_RESULT_INVALID_ARGUMENT; | 544 return MOJO_RESULT_INVALID_ARGUMENT; |
| 546 } | 545 } |
| 547 | 546 |
| 548 MojoResult Dispatcher::WaitSetRemoveImpl(uint64_t /*cookie*/) { | 547 MojoResult Dispatcher::WaitSetRemoveImpl(uint64_t /*cookie*/) { |
| 549 // See note above |WaitSetAddImpl()|. | 548 // See note above |WaitSetAddImpl()|. |
| 550 return MOJO_RESULT_INVALID_ARGUMENT; | 549 return MOJO_RESULT_INVALID_ARGUMENT; |
| 551 } | 550 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 // want to remove or weaken). | 675 // want to remove or weaken). |
| 677 MutexLocker locker(&mutex_); | 676 MutexLocker locker(&mutex_); |
| 678 #endif | 677 #endif |
| 679 | 678 |
| 680 return EndSerializeAndCloseImplNoLock(channel, destination, actual_size, | 679 return EndSerializeAndCloseImplNoLock(channel, destination, actual_size, |
| 681 platform_handles); | 680 platform_handles); |
| 682 } | 681 } |
| 683 | 682 |
| 684 } // namespace system | 683 } // namespace system |
| 685 } // namespace mojo | 684 } // namespace mojo |
| OLD | NEW |