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

Unified Diff: mojo/edk/system/node_controller.cc

Issue 2138343002: [mojo-edk] Ensure there is only one ProcessIncomingMessages() task posted to the IO thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment changes. Created 4 years, 5 months 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/node_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/node_controller.cc
diff --git a/mojo/edk/system/node_controller.cc b/mojo/edk/system/node_controller.cc
index a7f247a094387f86039b35db49690c0b9828381f..4dcd912a8fcd65953dcf05651e990dd8bbb0dc8f 100644
--- a/mojo/edk/system/node_controller.cc
+++ b/mojo/edk/system/node_controller.cc
@@ -651,6 +651,16 @@ void NodeController::AcceptIncomingMessages() {
void NodeController::ProcessIncomingMessages() {
RequestContext request_context(RequestContext::Source::SYSTEM);
+
+ {
+ base::AutoLock lock(messages_lock_);
+ // Allow a new incoming messages processing task to be posted. This can't be
+ // done after AcceptIncomingMessages() otherwise a message might be missed.
+ // Doing it here may result in at most two tasks existing at the same time;
+ // this running one, and one pending in the task runner.
+ incoming_messages_task_posted_ = false;
+ }
+
AcceptIncomingMessages();
}
@@ -708,16 +718,18 @@ void NodeController::ForwardMessage(const ports::NodeName& node,
// (synchronously) in response to Node's ClosePort, SendMessage, or
// AcceptMessage, we flush the queue after calling any of those methods.
base::AutoLock lock(messages_lock_);
- schedule_pump_task = incoming_messages_.empty();
+ // |io_task_runner_| may be null in tests or processes that don't require
+ // multi-process Mojo.
+ schedule_pump_task = incoming_messages_.empty() && io_task_runner_ &&
+ !incoming_messages_task_posted_;
+ incoming_messages_task_posted_ |= schedule_pump_task;
incoming_messages_.emplace(std::move(message));
incoming_messages_flag_.Set(true);
} else {
SendPeerMessage(node, std::move(message));
}
- // |io_task_runner_| may be null in tests or processes that don't require
- // multi-process Mojo.
- if (schedule_pump_task && io_task_runner_) {
+ if (schedule_pump_task) {
// Normally, the queue is processed after the action that added the local
// message is done (i.e. SendMessage, ClosePort, etc). However, it's also
// possible for a local message to be added as a result of a remote message,
« no previous file with comments | « mojo/edk/system/node_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698