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

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

Issue 2153733002: [mojo-edk] Prevent AcceptIncomingMessages flushing aggressively (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: -_- 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') | mojo/edk/system/watch_unittest.cc » ('j') | 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 28343b3a888831c613190d53574ee28ba5baefcd..63291a55f90319e541418e9ba0492dc53fb30d4c 100644
--- a/mojo/edk/system/node_controller.cc
+++ b/mojo/edk/system/node_controller.cc
@@ -652,29 +652,22 @@ void NodeController::SendPeerMessage(const ports::NodeName& name,
}
void NodeController::AcceptIncomingMessages() {
- while (incoming_messages_flag_) {
- // TODO: We may need to be more careful to avoid starving the rest of the
- // thread here. Revisit this if it turns out to be a problem. One
- // alternative would be to schedule a task to continue pumping messages
- // after flushing once.
-
- messages_lock_.Acquire();
- if (incoming_messages_.empty()) {
- messages_lock_.Release();
- break;
- }
- // libstdc++'s deque creates an internal buffer on construction, even when
- // the size is 0. So avoid creating it until it is necessary.
- std::queue<ports::ScopedMessage> messages;
- std::swap(messages, incoming_messages_);
- incoming_messages_flag_.Set(false);
- messages_lock_.Release();
-
- while (!messages.empty()) {
- node_->AcceptMessage(std::move(messages.front()));
- messages.pop();
+ {
+ base::AutoLock lock(messages_lock_);
+ if (!incoming_messages_.empty()) {
+ // libstdc++'s deque creates an internal buffer on construction, even when
+ // the size is 0. So avoid creating it until it is necessary.
+ std::queue<ports::ScopedMessage> messages;
+ std::swap(messages, incoming_messages_);
+ base::AutoUnlock unlock(messages_lock_);
+
+ while (!messages.empty()) {
+ node_->AcceptMessage(std::move(messages.front()));
+ messages.pop();
+ }
}
}
+
AttemptShutdownIfRequested();
}
@@ -753,7 +746,6 @@ void NodeController::ForwardMessage(const ports::NodeName& node,
!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));
}
« no previous file with comments | « mojo/edk/system/node_controller.h ('k') | mojo/edk/system/watch_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698