| 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/core.h" | 5 #include "mojo/edk/system/core.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "mojo/edk/embedder/platform_shared_buffer.h" | 11 #include "mojo/edk/embedder/platform_shared_buffer.h" |
| 11 #include "mojo/edk/embedder/platform_support.h" | 12 #include "mojo/edk/embedder/platform_support.h" |
| 12 #include "mojo/edk/system/async_waiter.h" | 13 #include "mojo/edk/system/async_waiter.h" |
| 13 #include "mojo/edk/system/configuration.h" | 14 #include "mojo/edk/system/configuration.h" |
| 14 #include "mojo/edk/system/data_pipe.h" | 15 #include "mojo/edk/system/data_pipe.h" |
| 15 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" | 16 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" |
| 16 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" | 17 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // INF. |Waiter| locks | 70 // INF. |Waiter| locks |
| 70 // | 71 // |
| 71 // Notes: | 72 // Notes: |
| 72 // - While holding a |Dispatcher| lock, you may not unconditionally attempt | 73 // - While holding a |Dispatcher| lock, you may not unconditionally attempt |
| 73 // to take another |Dispatcher| lock. (This has consequences on the | 74 // to take another |Dispatcher| lock. (This has consequences on the |
| 74 // concurrency semantics of |MojoWriteMessage()| when passing handles.) | 75 // concurrency semantics of |MojoWriteMessage()| when passing handles.) |
| 75 // Doing so would lead to deadlock. | 76 // Doing so would lead to deadlock. |
| 76 // - Locks at the "INF" level may not have any locks taken while they are | 77 // - Locks at the "INF" level may not have any locks taken while they are |
| 77 // held. | 78 // held. |
| 78 | 79 |
| 79 // TODO(vtl): This should take a |scoped_ptr<PlatformSupport>| as a parameter. | |
| 80 Core::Core(embedder::PlatformSupport* platform_support) | 80 Core::Core(embedder::PlatformSupport* platform_support) |
| 81 : platform_support_(platform_support) { | 81 : platform_support_(platform_support) { |
| 82 } | 82 } |
| 83 | 83 |
| 84 Core::~Core() { | 84 Core::~Core() { |
| 85 } | 85 } |
| 86 | 86 |
| 87 MojoHandle Core::AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher) { | 87 MojoHandle Core::AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher) { |
| 88 MutexLocker locker(&handle_table_mutex_); | 88 MutexLocker locker(&handle_table_mutex_); |
| 89 return handle_table_.AddDispatcher(dispatcher); | 89 return handle_table_.AddDispatcher(dispatcher); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 105 MutexLocker locker(&handle_table_mutex_); | 105 MutexLocker locker(&handle_table_mutex_); |
| 106 return handle_table_.GetAndRemoveDispatcher(handle, dispatcher); | 106 return handle_table_.GetAndRemoveDispatcher(handle, dispatcher); |
| 107 } | 107 } |
| 108 | 108 |
| 109 MojoResult Core::AsyncWait(MojoHandle handle, | 109 MojoResult Core::AsyncWait(MojoHandle handle, |
| 110 MojoHandleSignals signals, | 110 MojoHandleSignals signals, |
| 111 const base::Callback<void(MojoResult)>& callback) { | 111 const base::Callback<void(MojoResult)>& callback) { |
| 112 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle); | 112 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle); |
| 113 DCHECK(dispatcher); | 113 DCHECK(dispatcher); |
| 114 | 114 |
| 115 scoped_ptr<AsyncWaiter> waiter = make_scoped_ptr(new AsyncWaiter(callback)); | 115 std::unique_ptr<AsyncWaiter> waiter(new AsyncWaiter(callback)); |
| 116 MojoResult rv = dispatcher->AddAwakable(waiter.get(), signals, 0, nullptr); | 116 MojoResult rv = dispatcher->AddAwakable(waiter.get(), signals, 0, nullptr); |
| 117 if (rv == MOJO_RESULT_OK) | 117 if (rv == MOJO_RESULT_OK) |
| 118 ignore_result(waiter.release()); | 118 ignore_result(waiter.release()); |
| 119 return rv; | 119 return rv; |
| 120 } | 120 } |
| 121 | 121 |
| 122 MojoTimeTicks Core::GetTimeTicksNow() { | 122 MojoTimeTicks Core::GetTimeTicksNow() { |
| 123 return platform_support_->GetTimeTicksNow(); | 123 return platform_support_->GetTimeTicksNow(); |
| 124 } | 124 } |
| 125 | 125 |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 if (signals_states) { | 608 if (signals_states) { |
| 609 for (; i < num_handles; i++) | 609 for (; i < num_handles; i++) |
| 610 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); | 610 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); |
| 611 } | 611 } |
| 612 | 612 |
| 613 return rv; | 613 return rv; |
| 614 } | 614 } |
| 615 | 615 |
| 616 } // namespace system | 616 } // namespace system |
| 617 } // namespace mojo | 617 } // namespace mojo |
| OLD | NEW |