summaryrefslogtreecommitdiffstats
path: root/base/message_loop.cc
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-10 10:54:06 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-10 10:54:06 +0000
commitf886b7bf801cbdd2d9e4b31a8f74bc7490922cd4 (patch)
tree1ab6d88512e17de10c913cc163a31a7d5b2369bd /base/message_loop.cc
parent83c7264800194b0d9ffdce49c57a3fdd5cf6a1a0 (diff)
downloadchromium_src-f886b7bf801cbdd2d9e4b31a8f74bc7490922cd4.zip
chromium_src-f886b7bf801cbdd2d9e4b31a8f74bc7490922cd4.tar.gz
chromium_src-f886b7bf801cbdd2d9e4b31a8f74bc7490922cd4.tar.bz2
Move a bunch of code from the old to new TLS interface.
Review URL: http://codereview.chromium.org/1660 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1982 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop.cc')
-rw-r--r--base/message_loop.cc28
1 files changed, 19 insertions, 9 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc
index e90f0b2..3abf0c8 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -7,17 +7,16 @@
#include <algorithm>
#include "base/compiler_specific.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/message_pump_default.h"
#include "base/string_util.h"
-#include "base/thread_local_storage.h"
+#include "base/thread_local.h"
-// a TLS index to the message loop for the current thread
-// Note that if we start doing complex stuff in other static initializers
-// this could cause problems.
-// TODO(evanm): this shouldn't rely on static initialization.
-// static
-TLSSlot MessageLoop::tls_index_;
+// A lazily created thread local storage for quick access to a thread's message
+// loop, if one exists. This should be safe and free of static constructors.
+static base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr(
+ base::LINKER_INITIALIZED);
//------------------------------------------------------------------------------
@@ -55,14 +54,22 @@ static LPTOP_LEVEL_EXCEPTION_FILTER GetTopSEHFilter() {
//------------------------------------------------------------------------------
+// static
+MessageLoop* MessageLoop::current() {
+ // TODO(darin): sadly, we cannot enable this yet since people call us even
+ // when they have no intention of using us.
+ //DCHECK(loop) << "Ouch, did you forget to initialize me?";
+ return lazy_tls_ptr.Pointer()->Get();
+}
+
MessageLoop::MessageLoop(Type type)
: type_(type),
nestable_tasks_allowed_(true),
exception_restoration_(false),
state_(NULL),
next_sequence_num_(0) {
- DCHECK(!tls_index_.Get()) << "should only have one message loop per thread";
- tls_index_.Set(this);
+ DCHECK(!current()) << "should only have one message loop per thread";
+ lazy_tls_ptr.Pointer()->Set(this);
// TODO(darin): Choose the pump based on the requested type.
#if defined(OS_WIN)
@@ -83,6 +90,9 @@ MessageLoop::~MessageLoop() {
FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_,
WillDestroyCurrentMessageLoop());
+ // OK, now make it so that no one can find us.
+ lazy_tls_ptr.Pointer()->Set(NULL);
+
DCHECK(!state_);
// Clean up any unprocessed tasks, but take care: deleting a task could