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

Unified Diff: base/single_thread_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: SingleThreadTaskRunner::current() 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
« no previous file with comments | « base/single_thread_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/single_thread_task_runner.cc
diff --git a/base/single_thread_task_runner.cc b/base/single_thread_task_runner.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c0d0d50242701a0269b817480363fa65e5bd02b4
--- /dev/null
+++ b/base/single_thread_task_runner.cc
@@ -0,0 +1,30 @@
+// 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/single_thread_task_runner.h"
+
+#include "base/lazy_instance.h"
+#include "base/threading/thread_local.h"
+
+namespace base {
+
+namespace {
+
+base::LazyInstance<base::ThreadLocalPointer<SingleThreadTaskRunner> >
+ lazy_tls_ptr = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+// static
+scoped_refptr<SingleThreadTaskRunner> SingleThreadTaskRunner::current() {
+ return lazy_tls_ptr.Pointer()->Get();
Ami GONE FROM CHROMIUM 2012/04/25 17:27:55 Can this DCHECK the ret value (see the TODO(darin)
Sergey Ulanov 2012/04/30 20:02:10 Done.
+}
+
+// static
+void SingleThreadTaskRunner::SetCurrent(SingleThreadTaskRunner* new_current) {
+ DCHECK(!current() || !new_current);
Ami GONE FROM CHROMIUM 2012/04/25 17:27:55 WDYT of xor instead of !||! ? DCHECK(current() ^ n
Sergey Ulanov 2012/04/30 20:02:10 ^ is bitwise xor, so I'm not sure it would work wi
+ lazy_tls_ptr.Pointer()->Set(new_current);
+}
+
+} // namespace base
« no previous file with comments | « base/single_thread_task_runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698