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

Unified Diff: base/thread_main_task_runner.cc

Issue 10210008: Make MessageLoopProxy::current() usable on threads that don't have MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
« base/thread_main_task_runner.h ('K') | « base/thread_main_task_runner.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/thread_main_task_runner.cc
diff --git a/base/thread_main_task_runner.cc b/base/thread_main_task_runner.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ca68bb7d7f01877629cf8cde224ef701711e3a11
--- /dev/null
+++ b/base/thread_main_task_runner.cc
@@ -0,0 +1,32 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/thread_main_task_runner.h"
+
+#include "base/lazy_instance.h"
+#include "base/threading/thread_local.h"
+
+namespace base {
+
+namespace {
+
+base::LazyInstance<base::ThreadLocalPointer<ThreadMainTaskRunner> >
+ lazy_tls_ptr = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+// static
+scoped_refptr<ThreadMainTaskRunner> ThreadMainTaskRunner::current() {
+ ThreadMainTaskRunner* result = lazy_tls_ptr.Pointer()->Get();
+ DCHECK(result);
+ return result;
+}
+
+// static
+void ThreadMainTaskRunner::SetCurrent(ThreadMainTaskRunner* new_current) {
+ DCHECK(!current() || !new_current);
Ami GONE FROM CHROMIUM 2012/04/30 23:34:05 I'm surprised this doesn't DCHECK-fail the first t
Ami GONE FROM CHROMIUM 2012/04/30 23:34:05 (assuming you s/current()/lazy_tls_ptr.Pointer()->
Sergey Ulanov 2012/05/01 00:34:54 Oops, I didn't test this code after adding DCHECK
Sergey Ulanov 2012/05/01 00:34:54 No. Ok, I changed this code to check this case too
+ lazy_tls_ptr.Pointer()->Set(new_current);
+}
+
+} // namespace base
« base/thread_main_task_runner.h ('K') | « base/thread_main_task_runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698