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

Side by Side Diff: base/threading/thread.cc

Issue 8491043: Allow linker initialization of lazy instance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: willchan comments + rebase Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/threading/platform_thread_posix.cc ('k') | base/threading/thread_restrictions.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/threading/thread.h" 5 #include "base/threading/thread.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 8 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
9 #include "base/threading/thread_local.h" 9 #include "base/threading/thread_local.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
11 11
12 namespace base { 12 namespace base {
13 13
14 namespace { 14 namespace {
15 15
16 // We use this thread-local variable to record whether or not a thread exited 16 // We use this thread-local variable to record whether or not a thread exited
17 // because its Stop method was called. This allows us to catch cases where 17 // because its Stop method was called. This allows us to catch cases where
18 // MessageLoop::Quit() is called directly, which is unexpected when using a 18 // MessageLoop::Quit() is called directly, which is unexpected when using a
19 // Thread to setup and run a MessageLoop. 19 // Thread to setup and run a MessageLoop.
20 base::LazyInstance<base::ThreadLocalBoolean> lazy_tls_bool( 20 base::LazyInstance<base::ThreadLocalBoolean> lazy_tls_bool =
21 base::LINKER_INITIALIZED); 21 LAZY_INSTANCE_INITIALIZER;
22 22
23 } // namespace 23 } // namespace
24 24
25 // This task is used to trigger the message loop to exit. 25 // This task is used to trigger the message loop to exit.
26 class ThreadQuitTask : public Task { 26 class ThreadQuitTask : public Task {
27 public: 27 public:
28 virtual void Run() { 28 virtual void Run() {
29 MessageLoop::current()->Quit(); 29 MessageLoop::current()->Quit();
30 Thread::SetThreadWasQuitProperly(true); 30 Thread::SetThreadWasQuitProperly(true);
31 } 31 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // Assert that MessageLoop::Quit was called by ThreadQuitTask. 168 // Assert that MessageLoop::Quit was called by ThreadQuitTask.
169 DCHECK(GetThreadWasQuitProperly()); 169 DCHECK(GetThreadWasQuitProperly());
170 170
171 // We can't receive messages anymore. 171 // We can't receive messages anymore.
172 message_loop_ = NULL; 172 message_loop_ = NULL;
173 } 173 }
174 thread_id_ = kInvalidThreadId; 174 thread_id_ = kInvalidThreadId;
175 } 175 }
176 176
177 } // namespace base 177 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/platform_thread_posix.cc ('k') | base/threading/thread_restrictions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698