| 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/system/core.h" | 5 #include "mojo/system/core.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "mojo/embedder/platform_shared_buffer.h" | 11 #include "mojo/embedder/platform_shared_buffer.h" |
| 12 #include "mojo/embedder/platform_support.h" |
| 12 #include "mojo/embedder/simple_platform_support.h" // TODO(vtl): Remove this. | 13 #include "mojo/embedder/simple_platform_support.h" // TODO(vtl): Remove this. |
| 13 #include "mojo/public/c/system/macros.h" | 14 #include "mojo/public/c/system/macros.h" |
| 14 #include "mojo/system/constants.h" | 15 #include "mojo/system/constants.h" |
| 15 #include "mojo/system/data_pipe.h" | 16 #include "mojo/system/data_pipe.h" |
| 16 #include "mojo/system/data_pipe_consumer_dispatcher.h" | 17 #include "mojo/system/data_pipe_consumer_dispatcher.h" |
| 17 #include "mojo/system/data_pipe_producer_dispatcher.h" | 18 #include "mojo/system/data_pipe_producer_dispatcher.h" |
| 18 #include "mojo/system/dispatcher.h" | 19 #include "mojo/system/dispatcher.h" |
| 19 #include "mojo/system/handle_signals_state.h" | 20 #include "mojo/system/handle_signals_state.h" |
| 20 #include "mojo/system/local_data_pipe.h" | 21 #include "mojo/system/local_data_pipe.h" |
| 21 #include "mojo/system/memory.h" | 22 #include "mojo/system/memory.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // INF. |Waiter| locks | 69 // INF. |Waiter| locks |
| 69 // | 70 // |
| 70 // Notes: | 71 // Notes: |
| 71 // - While holding a |Dispatcher| lock, you may not unconditionally attempt | 72 // - While holding a |Dispatcher| lock, you may not unconditionally attempt |
| 72 // to take another |Dispatcher| lock. (This has consequences on the | 73 // to take another |Dispatcher| lock. (This has consequences on the |
| 73 // concurrency semantics of |MojoWriteMessage()| when passing handles.) | 74 // concurrency semantics of |MojoWriteMessage()| when passing handles.) |
| 74 // Doing so would lead to deadlock. | 75 // Doing so would lead to deadlock. |
| 75 // - Locks at the "INF" level may not have any locks taken while they are | 76 // - Locks at the "INF" level may not have any locks taken while they are |
| 76 // held. | 77 // held. |
| 77 | 78 |
| 78 Core::Core() { | 79 // TODO(vtl): This should take a |scoped_ptr<PlatformSupport>| as a parameter. |
| 80 Core::Core() : platform_support_(new embedder::SimplePlatformSupport()) { |
| 79 } | 81 } |
| 80 | 82 |
| 81 Core::~Core() { | 83 Core::~Core() { |
| 82 } | 84 } |
| 83 | 85 |
| 84 MojoHandle Core::AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher) { | 86 MojoHandle Core::AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher) { |
| 85 base::AutoLock locker(handle_table_lock_); | 87 base::AutoLock locker(handle_table_lock_); |
| 86 return handle_table_.AddDispatcher(dispatcher); | 88 return handle_table_.AddDispatcher(dispatcher); |
| 87 } | 89 } |
| 88 | 90 |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 MojoResult Core::CreateSharedBuffer( | 458 MojoResult Core::CreateSharedBuffer( |
| 457 UserPointer<const MojoCreateSharedBufferOptions> options, | 459 UserPointer<const MojoCreateSharedBufferOptions> options, |
| 458 uint64_t num_bytes, | 460 uint64_t num_bytes, |
| 459 UserPointer<MojoHandle> shared_buffer_handle) { | 461 UserPointer<MojoHandle> shared_buffer_handle) { |
| 460 MojoCreateSharedBufferOptions validated_options = {}; | 462 MojoCreateSharedBufferOptions validated_options = {}; |
| 461 MojoResult result = SharedBufferDispatcher::ValidateCreateOptions( | 463 MojoResult result = SharedBufferDispatcher::ValidateCreateOptions( |
| 462 options, &validated_options); | 464 options, &validated_options); |
| 463 if (result != MOJO_RESULT_OK) | 465 if (result != MOJO_RESULT_OK) |
| 464 return result; | 466 return result; |
| 465 | 467 |
| 466 // TODO(vtl): |Core| should have a |PlatformSupport| passed in at creation | |
| 467 // time, and we should use that instead. | |
| 468 embedder::SimplePlatformSupport platform_support; | |
| 469 scoped_refptr<SharedBufferDispatcher> dispatcher; | 468 scoped_refptr<SharedBufferDispatcher> dispatcher; |
| 470 result = SharedBufferDispatcher::Create( | 469 result = SharedBufferDispatcher::Create( |
| 471 &platform_support, validated_options, num_bytes, &dispatcher); | 470 platform_support(), validated_options, num_bytes, &dispatcher); |
| 472 if (result != MOJO_RESULT_OK) { | 471 if (result != MOJO_RESULT_OK) { |
| 473 DCHECK(!dispatcher); | 472 DCHECK(!dispatcher); |
| 474 return result; | 473 return result; |
| 475 } | 474 } |
| 476 | 475 |
| 477 MojoHandle h = AddDispatcher(dispatcher); | 476 MojoHandle h = AddDispatcher(dispatcher); |
| 478 if (h == MOJO_HANDLE_INVALID) { | 477 if (h == MOJO_HANDLE_INVALID) { |
| 479 LOG(ERROR) << "Handle table full"; | 478 LOG(ERROR) << "Handle table full"; |
| 480 dispatcher->Close(); | 479 dispatcher->Close(); |
| 481 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 480 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 if (signals_states) { | 597 if (signals_states) { |
| 599 for (; i < num_handles; i++) | 598 for (; i < num_handles; i++) |
| 600 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); | 599 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); |
| 601 } | 600 } |
| 602 | 601 |
| 603 return rv; | 602 return rv; |
| 604 } | 603 } |
| 605 | 604 |
| 606 } // namespace system | 605 } // namespace system |
| 607 } // namespace mojo | 606 } // namespace mojo |
| OLD | NEW |