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

Unified Diff: mojo/edk/system/wait_set_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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/system/wait_set_dispatcher.h ('k') | mojo/edk/system/wait_set_dispatcher_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/wait_set_dispatcher.cc
diff --git a/third_party/mojo/src/mojo/edk/system/wait_set_dispatcher.cc b/mojo/edk/system/wait_set_dispatcher.cc
similarity index 84%
copy from third_party/mojo/src/mojo/edk/system/wait_set_dispatcher.cc
copy to mojo/edk/system/wait_set_dispatcher.cc
index 45518e7eefd14044f2696bca00dd8fce301cfc31..3a667df2c11d10edf3bda9d3b4bc5da9a7d0d61f 100644
--- a/third_party/mojo/src/mojo/edk/system/wait_set_dispatcher.cc
+++ b/mojo/edk/system/wait_set_dispatcher.cc
@@ -2,16 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "third_party/mojo/src/mojo/edk/system/wait_set_dispatcher.h"
+#include "mojo/edk/system/wait_set_dispatcher.h"
#include <algorithm>
#include <utility>
#include "base/logging.h"
-#include "third_party/mojo/src/mojo/edk/system/awakable.h"
+#include "mojo/edk/system/awakable.h"
namespace mojo {
-namespace system {
+namespace edk {
class WaitSetDispatcher::Waiter final : public Awakable {
public:
@@ -30,6 +30,10 @@ class WaitSetDispatcher::Waiter final : public Awakable {
WaitSetDispatcher* const dispatcher_;
};
+WaitSetDispatcher::WaitState::WaitState() {}
+
+WaitSetDispatcher::WaitState::~WaitState() {}
+
WaitSetDispatcher::WaitSetDispatcher()
: waiter_(new WaitSetDispatcher::Waiter(this)) {}
@@ -44,12 +48,12 @@ Dispatcher::Type WaitSetDispatcher::GetType() const {
}
void WaitSetDispatcher::CloseImplNoLock() {
- mutex().AssertHeld();
+ lock().AssertAcquired();
for (const auto& entry : waiting_dispatchers_)
entry.second.dispatcher->RemoveAwakable(waiter_.get(), nullptr);
waiting_dispatchers_.clear();
- MutexLocker locker(&awoken_mutex_);
+ base::AutoLock locker(awoken_lock_);
awoken_queue_.clear();
processed_dispatchers_.clear();
}
@@ -58,7 +62,7 @@ MojoResult WaitSetDispatcher::AddWaitingDispatcherImplNoLock(
const scoped_refptr<Dispatcher>& dispatcher,
MojoHandleSignals signals,
uintptr_t context) {
- mutex().AssertHeld();
+ lock().AssertAcquired();
if (dispatcher == this)
return MOJO_RESULT_INVALID_ARGUMENT;
@@ -81,9 +85,8 @@ MojoResult WaitSetDispatcher::AddWaitingDispatcherImplNoLock(
state.dispatcher = dispatcher;
state.context = context;
state.signals = signals;
- bool inserted =
- waiting_dispatchers_.insert(std::make_pair(dispatcher_handle, state))
- .second;
+ bool inserted = waiting_dispatchers_.insert(
+ std::make_pair(dispatcher_handle, state)).second;
DCHECK(inserted);
return MOJO_RESULT_OK;
@@ -91,7 +94,7 @@ MojoResult WaitSetDispatcher::AddWaitingDispatcherImplNoLock(
MojoResult WaitSetDispatcher::RemoveWaitingDispatcherImplNoLock(
const scoped_refptr<Dispatcher>& dispatcher) {
- mutex().AssertHeld();
+ lock().AssertAcquired();
uintptr_t dispatcher_handle = reinterpret_cast<uintptr_t>(dispatcher.get());
auto it = waiting_dispatchers_.find(dispatcher_handle);
if (it == waiting_dispatchers_.end())
@@ -102,7 +105,7 @@ MojoResult WaitSetDispatcher::RemoveWaitingDispatcherImplNoLock(
// |dispatcher|.
waiting_dispatchers_.erase(it);
- MutexLocker locker(&awoken_mutex_);
+ base::AutoLock locker(awoken_lock_);
int num_erased = 0;
for (auto it = awoken_queue_.begin(); it != awoken_queue_.end();) {
if (it->first == dispatcher_handle) {
@@ -123,11 +126,11 @@ MojoResult WaitSetDispatcher::RemoveWaitingDispatcherImplNoLock(
}
MojoResult WaitSetDispatcher::GetReadyDispatchersImplNoLock(
- UserPointer<uint32_t> count,
+ uint32_t* count,
DispatcherVector* dispatchers,
- UserPointer<MojoResult> results,
- UserPointer<uintptr_t> contexts) {
- mutex().AssertHeld();
+ MojoResult* results,
+ uintptr_t* contexts) {
+ lock().AssertAcquired();
dispatchers->clear();
// Re-queue any already retrieved dispatchers. These should be the dispatchers
@@ -138,7 +141,7 @@ MojoResult WaitSetDispatcher::GetReadyDispatchersImplNoLock(
// handle/signal continues to return immediately.
std::deque<uintptr_t> pending;
{
- MutexLocker locker(&awoken_mutex_);
+ base::AutoLock locker(awoken_lock_);
pending.swap(processed_dispatchers_);
}
for (uintptr_t d : pending) {
@@ -165,10 +168,10 @@ MojoResult WaitSetDispatcher::GetReadyDispatchersImplNoLock(
}
}
- const uint32_t max_woken = count.Get();
+ const uint32_t max_woken = *count;
uint32_t num_woken = 0;
- MutexLocker locker(&awoken_mutex_);
+ base::AutoLock locker(awoken_lock_);
while (!awoken_queue_.empty() && num_woken < max_woken) {
uintptr_t d = awoken_queue_.front().first;
MojoResult result = awoken_queue_.front().second;
@@ -177,21 +180,23 @@ MojoResult WaitSetDispatcher::GetReadyDispatchersImplNoLock(
auto it = waiting_dispatchers_.find(d);
DCHECK(it != waiting_dispatchers_.end());
- results.At(num_woken).Put(result);
+ results[num_woken] = result;
dispatchers->push_back(it->second.dispatcher);
- if (!contexts.IsNull())
- contexts.At(num_woken).Put(it->second.context);
+ if (contexts)
+ contexts[num_woken] = it->second.context;
if (result != MOJO_RESULT_CANCELLED) {
processed_dispatchers_.push_back(d);
} else {
+ // |MOJO_RESULT_CANCELLED| indicates that the dispatcher was closed.
+ // Return it, but also implcitly remove it from the wait set.
waiting_dispatchers_.erase(it);
}
num_woken++;
}
- count.Put(num_woken);
+ *count = num_woken;
if (!num_woken)
return MOJO_RESULT_SHOULD_WAIT;
@@ -199,8 +204,8 @@ MojoResult WaitSetDispatcher::GetReadyDispatchersImplNoLock(
}
void WaitSetDispatcher::CancelAllAwakablesNoLock() {
- mutex().AssertHeld();
- MutexLocker locker(&awakable_mutex_);
+ lock().AssertAcquired();
+ base::AutoLock locker(awakable_lock_);
awakable_list_.CancelAll();
}
@@ -209,7 +214,7 @@ MojoResult WaitSetDispatcher::AddAwakableImplNoLock(
MojoHandleSignals signals,
uintptr_t context,
HandleSignalsState* signals_state) {
- mutex().AssertHeld();
+ lock().AssertAcquired();
HandleSignalsState state(GetHandleSignalsStateImplNoLock());
if (state.satisfies(signals)) {
@@ -223,7 +228,7 @@ MojoResult WaitSetDispatcher::AddAwakableImplNoLock(
return MOJO_RESULT_FAILED_PRECONDITION;
}
- MutexLocker locker(&awakable_mutex_);
+ base::AutoLock locker(awakable_lock_);
awakable_list_.Add(awakable, signals, context);
return MOJO_RESULT_OK;
}
@@ -231,18 +236,18 @@ MojoResult WaitSetDispatcher::AddAwakableImplNoLock(
void WaitSetDispatcher::RemoveAwakableImplNoLock(
Awakable* awakable,
HandleSignalsState* signals_state) {
- mutex().AssertHeld();
- MutexLocker locker(&awakable_mutex_);
+ lock().AssertAcquired();
+ base::AutoLock locker(awakable_lock_);
awakable_list_.Remove(awakable);
if (signals_state)
*signals_state = GetHandleSignalsStateImplNoLock();
}
HandleSignalsState WaitSetDispatcher::GetHandleSignalsStateImplNoLock() const {
- mutex().AssertHeld();
+ lock().AssertAcquired();
HandleSignalsState rv;
rv.satisfiable_signals = MOJO_HANDLE_SIGNAL_READABLE;
- MutexLocker locker(&awoken_mutex_);
+ base::AutoLock locker(awoken_lock_);
if (!awoken_queue_.empty() || !processed_dispatchers_.empty())
rv.satisfied_signals = MOJO_HANDLE_SIGNAL_READABLE;
return rv;
@@ -250,7 +255,7 @@ HandleSignalsState WaitSetDispatcher::GetHandleSignalsStateImplNoLock() const {
scoped_refptr<Dispatcher>
WaitSetDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
- mutex().AssertHeld();
+ lock().AssertAcquired();
LOG(ERROR) << "Attempting to serialize WaitSet";
CloseImplNoLock();
return new WaitSetDispatcher();
@@ -258,7 +263,7 @@ WaitSetDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
void WaitSetDispatcher::WakeDispatcher(MojoResult result, uintptr_t context) {
{
- MutexLocker locker(&awoken_mutex_);
+ base::AutoLock locker(awoken_lock_);
if (result == MOJO_RESULT_ALREADY_EXISTS)
result = MOJO_RESULT_OK;
@@ -266,12 +271,12 @@ void WaitSetDispatcher::WakeDispatcher(MojoResult result, uintptr_t context) {
awoken_queue_.push_back(std::make_pair(context, result));
}
- MutexLocker locker(&awakable_mutex_);
+ base::AutoLock locker(awakable_lock_);
HandleSignalsState signals_state;
signals_state.satisfiable_signals = MOJO_HANDLE_SIGNAL_READABLE;
signals_state.satisfied_signals = MOJO_HANDLE_SIGNAL_READABLE;
awakable_list_.AwakeForStateChange(signals_state);
}
-} // namespace system
+} // namespace edk
} // namespace mojo
« no previous file with comments | « mojo/edk/system/wait_set_dispatcher.h ('k') | mojo/edk/system/wait_set_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698