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

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

Issue 2209733002: [mojo-edk] Prevent AcceptIncomingMessages flushing aggressively (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 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 5fc55f557d7063cd50071b398a17f90bdc5d320d..e6ecc0d62881c011d890b4d206c60d90e478f7d3 100644
--- a/mojo/edk/system/node_controller.cc
+++ b/mojo/edk/system/node_controller.cc
@@ -620,29 +620,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();
}
@@ -700,7 +693,6 @@ void NodeController::ForwardMessage(const ports::NodeName& node,
// AcceptMessage, we flush the queue after calling any of those methods.
base::AutoLock lock(messages_lock_);
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