Chromium Code Reviews| 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 |