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

Unified Diff: mojo/common/message_pump_mojo.cc

Issue 506353002: Make HandleWatcher watch on the same thread if the thread is running a MessagePumpMojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated unittests Created 6 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
Index: mojo/common/message_pump_mojo.cc
diff --git a/mojo/common/message_pump_mojo.cc b/mojo/common/message_pump_mojo.cc
index a2275925876143315fa45f61d0b98c7fbe0fbbfc..91b78d1ae4fde79c967bbca657a118119f8efbc5 100644
--- a/mojo/common/message_pump_mojo.cc
+++ b/mojo/common/message_pump_mojo.cc
@@ -8,7 +8,9 @@
#include <vector>
#include "base/debug/alias.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
+#include "base/threading/thread_local.h"
#include "base/time/time.h"
#include "mojo/common/message_pump_mojo_handler.h"
#include "mojo/common/time_helper.h"
@@ -17,6 +19,9 @@ namespace mojo {
namespace common {
namespace {
+base::LazyInstance<base::ThreadLocalPointer<MessagePumpMojo> >::Leaky
+ g_tls_current_pump = LAZY_INSTANCE_INITIALIZER;
+
MojoDeadline TimeTicksToMojoDeadline(base::TimeTicks time_ticks,
base::TimeTicks now) {
// The is_null() check matches that of HandleWatcher as well as how
@@ -52,9 +57,14 @@ struct MessagePumpMojo::RunState {
};
MessagePumpMojo::MessagePumpMojo() : run_state_(NULL), next_handler_id_(0) {
+ DCHECK(!current())
+ << "There is already a MessagePumpMojo instance on this thread.";
+ g_tls_current_pump.Pointer()->Set(this);
}
MessagePumpMojo::~MessagePumpMojo() {
+ DCHECK_EQ(this, current());
+ g_tls_current_pump.Pointer()->Set(NULL);
}
// static
@@ -62,6 +72,11 @@ scoped_ptr<base::MessagePump> MessagePumpMojo::Create() {
return scoped_ptr<MessagePump>(new MessagePumpMojo());
}
+// static
+MessagePumpMojo* MessagePumpMojo::current() {
+ return g_tls_current_pump.Pointer()->Get();
+}
+
void MessagePumpMojo::AddHandler(MessagePumpMojoHandler* handler,
const Handle& handle,
MojoHandleSignals wait_signals,

Powered by Google App Engine
This is Rietveld 408576698