From 51fec73df69c66596985a9037bc0665529327507 Mon Sep 17 00:00:00 2001 From: yzshen Date: Wed, 16 Mar 2016 12:46:44 -0700 Subject: Mojo C++ bindings: MultiplexRouter more aggressively dispatch queued messages. This CL allows MultiplexRouter to dispatch multiple queued messages to clients without returning to the message loop. This way we may starve other tasks on the same thread, but we have been doing the same thing in the non-associated-interface case (see Connector::ReadAllAvailableMessages). So it is probably okay. BUG=590495 Review URL: https://codereview.chromium.org/1808583003 Cr-Commit-Position: refs/heads/master@{#381514} --- mojo/public/cpp/bindings/lib/multiplex_router.cc | 15 ++++++--------- mojo/public/cpp/bindings/lib/multiplex_router.h | 6 ++---- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/mojo/public/cpp/bindings/lib/multiplex_router.cc b/mojo/public/cpp/bindings/lib/multiplex_router.cc index 48d8393..ca22e86 100644 --- a/mojo/public/cpp/bindings/lib/multiplex_router.cc +++ b/mojo/public/cpp/bindings/lib/multiplex_router.cc @@ -403,8 +403,8 @@ void MultiplexRouter::ProcessTasks(bool force_async) { tasks_.pop_front(); bool processed = task->IsNotifyErrorTask() - ? ProcessNotifyErrorTask(task.get(), &force_async) - : ProcessIncomingMessageTask(task.get(), &force_async); + ? ProcessNotifyErrorTask(task.get(), force_async) + : ProcessIncomingMessageTask(task.get(), force_async); if (!processed) { tasks_.push_front(std::move(task)); @@ -413,19 +413,18 @@ void MultiplexRouter::ProcessTasks(bool force_async) { } } -bool MultiplexRouter::ProcessNotifyErrorTask(Task* task, bool* force_async) { +bool MultiplexRouter::ProcessNotifyErrorTask(Task* task, bool force_async) { lock_.AssertAcquired(); InterfaceEndpoint* endpoint = task->endpoint_to_notify.get(); if (!endpoint->client()) return true; - if (!endpoint->task_runner()->BelongsToCurrentThread() || *force_async) { + if (!endpoint->task_runner()->BelongsToCurrentThread() || force_async) { endpoint->task_runner()->PostTask( FROM_HERE, base::Bind(&MultiplexRouter::LockAndCallProcessTasks, this)); return false; } - *force_async = true; InterfaceEndpointClient* client = endpoint->client(); { // We must unlock before calling into |client| because it may call this @@ -439,8 +438,7 @@ bool MultiplexRouter::ProcessNotifyErrorTask(Task* task, bool* force_async) { return true; } -bool MultiplexRouter::ProcessIncomingMessageTask(Task* task, - bool* force_async) { +bool MultiplexRouter::ProcessIncomingMessageTask(Task* task, bool force_async) { lock_.AssertAcquired(); Message* message = task->message.get(); @@ -479,13 +477,12 @@ bool MultiplexRouter::ProcessIncomingMessageTask(Task* task, return false; } - if (!endpoint->task_runner()->BelongsToCurrentThread() || *force_async) { + if (!endpoint->task_runner()->BelongsToCurrentThread() || force_async) { endpoint->task_runner()->PostTask( FROM_HERE, base::Bind(&MultiplexRouter::LockAndCallProcessTasks, this)); return false; } - *force_async = true; InterfaceEndpointClient* client = endpoint->client(); scoped_ptr owned_message = std::move(task->message); bool result = false; diff --git a/mojo/public/cpp/bindings/lib/multiplex_router.h b/mojo/public/cpp/bindings/lib/multiplex_router.h index d2ce406..f66d202 100644 --- a/mojo/public/cpp/bindings/lib/multiplex_router.h +++ b/mojo/public/cpp/bindings/lib/multiplex_router.h @@ -174,10 +174,8 @@ class MultiplexRouter // Returns true to indicate that |task| has been processed. Otherwise the task // will be added back to the front of the queue. - // |*force_async| may be set to true to force subsequent tasks being processed - // in an asynchronous manner. - bool ProcessNotifyErrorTask(Task* task, bool* force_async); - bool ProcessIncomingMessageTask(Task* task, bool* force_async); + bool ProcessNotifyErrorTask(Task* task, bool force_async); + bool ProcessIncomingMessageTask(Task* task, bool force_async); void LockAndCallProcessTasks(); -- cgit v1.1