diff options
author | evanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-20 22:11:47 +0000 |
---|---|---|
committer | evanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-20 22:11:47 +0000 |
commit | fa87a2527ca8c0bcef92d8e44791332782936911 (patch) | |
tree | 04dc5d1e6881f8356f91203a386648057b20d924 /chrome | |
parent | 4f64d0af5908e36d356c834005d08cca98d579fe (diff) | |
download | chromium_src-fa87a2527ca8c0bcef92d8e44791332782936911.zip chromium_src-fa87a2527ca8c0bcef92d8e44791332782936911.tar.gz chromium_src-fa87a2527ca8c0bcef92d8e44791332782936911.tar.bz2 |
Revert. Failing unit tests.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1118 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/common/ipc_sync_channel.cc | 12 | ||||
-rw-r--r-- | chrome/common/notification_service.cc | 10 | ||||
-rw-r--r-- | chrome/common/notification_service.h | 7 | ||||
-rw-r--r-- | chrome/common/rand_util.cc | 7 | ||||
-rw-r--r-- | chrome/renderer/render_thread.cc | 8 | ||||
-rw-r--r-- | chrome/renderer/render_thread.h | 4 |
6 files changed, 23 insertions, 25 deletions
diff --git a/chrome/common/ipc_sync_channel.cc b/chrome/common/ipc_sync_channel.cc index 3932c6d..25a22c8 100644 --- a/chrome/common/ipc_sync_channel.cc +++ b/chrome/common/ipc_sync_channel.cc @@ -57,8 +57,7 @@ namespace IPC { // sync message while another one is blocked). // Holds a pointer to the per-thread ReceivedSyncMsgQueue object. -// TODO(evanm): this shouldn't rely on static initialization. -static TLSSlot g_tls_index; +static int g_tls_index = ThreadLocalStorage::Alloc(); class SyncChannel::ReceivedSyncMsgQueue : public base::RefCountedThreadSafe<ReceivedSyncMsgQueue> { @@ -70,10 +69,10 @@ class SyncChannel::ReceivedSyncMsgQueue : } ~ReceivedSyncMsgQueue() { - DCHECK(g_tls_index.Get()); + DCHECK(ThreadLocalStorage::Get(g_tls_index)); DCHECK(MessageLoop::current() == listener_message_loop_); CloseHandle(blocking_event_); - g_tls_index.Set(NULL); + ThreadLocalStorage::Set(g_tls_index, NULL); } // Called on IPC thread when a synchronous message or reply arrives. @@ -238,13 +237,14 @@ SyncChannel::SyncContext::SyncContext( reply_deserialize_result_(false) { // We want one ReceivedSyncMsgQueue per listener thread (i.e. since multiple // SyncChannel objects that can block the same thread). - received_sync_msgs_ = static_cast<ReceivedSyncMsgQueue*>(g_tls_index.Get()); + received_sync_msgs_ = static_cast<ReceivedSyncMsgQueue*>( + ThreadLocalStorage::Get(g_tls_index)); if (!received_sync_msgs_) { // Stash a pointer to the listener thread's ReceivedSyncMsgQueue, as we // need to be able to access it in the IPC thread. received_sync_msgs_ = new ReceivedSyncMsgQueue(); - g_tls_index.Set(received_sync_msgs_); + ThreadLocalStorage::Set(g_tls_index, received_sync_msgs_); } // Addref manually so that we can ensure destruction on the listener thread diff --git a/chrome/common/notification_service.cc b/chrome/common/notification_service.cc index 2345ba0..672052f 100644 --- a/chrome/common/notification_service.cc +++ b/chrome/common/notification_service.cc @@ -29,11 +29,9 @@ #include "chrome/common/notification_service.h" -// TODO(evanm): This shouldn't depend on static initialization. -// static -TLSSlot NotificationService::tls_index_; +int NotificationService::tls_index_ = ThreadLocalStorage::Alloc(); -// static +/* static */ bool NotificationService::HasKey(const NotificationSourceMap& map, const NotificationSource& source) { return map.find(source.map_key()) != map.end(); @@ -45,7 +43,7 @@ NotificationService::NotificationService() { memset(observer_counts_, 0, sizeof(observer_counts_)); #endif - tls_index_.Set(this); + ThreadLocalStorage::Set(tls_index_, this); } void NotificationService::AddObserver(NotificationObserver* observer, @@ -119,7 +117,7 @@ void NotificationService::Notify(NotificationType type, NotificationService::~NotificationService() { - tls_index_.Set(NULL); + ThreadLocalStorage::Set(tls_index_, NULL); #ifndef NDEBUG for (int i = 0; i < NOTIFICATION_TYPE_COUNT; i++) { diff --git a/chrome/common/notification_service.h b/chrome/common/notification_service.h index 6ad58d0..1243748 100644 --- a/chrome/common/notification_service.h +++ b/chrome/common/notification_service.h @@ -36,8 +36,8 @@ #include <map> -#include "base/observer_list.h" #include "base/thread_local_storage.h" +#include "base/observer_list.h" #include "base/values.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_source.h" @@ -50,7 +50,8 @@ class NotificationService { // Returns the NotificationService object for the current thread, or NULL if // none. static NotificationService* current() { - return static_cast<NotificationService *>(tls_index_.Get()); + return static_cast<NotificationService *>( + ThreadLocalStorage::Get(tls_index_)); } // Normally instantiated when the thread is created. Not all threads have @@ -118,7 +119,7 @@ class NotificationService { // The thread local storage index, used for getting the current thread's // instance. - static TLSSlot tls_index_; + static int tls_index_; #ifndef NDEBUG // Used to check to see that AddObserver and RemoveObserver calls are diff --git a/chrome/common/rand_util.cc b/chrome/common/rand_util.cc index d6c2824..13c586f 100644 --- a/chrome/common/rand_util.cc +++ b/chrome/common/rand_util.cc @@ -39,13 +39,12 @@ namespace rand_util { -// TODO(evanm): don't rely on static initialization. // Using TLS since srand() needs to be called once in each thread. -TLSSlot g_tls_index; +int g_tls_index = ThreadLocalStorage::Alloc(); int RandInt(int min, int max) { - if (g_tls_index.Get() == 0) { - g_tls_index.Set(reinterpret_cast<void*>(1)); + if (ThreadLocalStorage::Get(g_tls_index) == 0) { + ThreadLocalStorage::Set(g_tls_index, reinterpret_cast<void*>(1)); TimeDelta now = TimeTicks::UnreliableHighResNow() - TimeTicks(); unsigned int seed = static_cast<unsigned int>(now.InMicroseconds()); srand(seed); diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index 14f9313..b37cf454 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -47,9 +47,8 @@ static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; // V8 needs a 1MB stack size. static const size_t kStackSize = 1024 * 1024; -// TODO(evanm): don't rely on static initialization. -// static -TLSSlot RenderThread::tls_index_; +/*static*/ +DWORD RenderThread::tls_index_ = ThreadLocalStorage::Alloc(); //----------------------------------------------------------------------------- // Methods below are only called on the owner's thread: @@ -107,6 +106,7 @@ void RenderThread::RemoveRoute(int32 routing_id) { } void RenderThread::Init() { + DCHECK(tls_index_) << "static initializer failed"; DCHECK(!current()) << "should only have one RenderThread per thread"; notification_service_.reset(new NotificationService); @@ -118,7 +118,7 @@ void RenderThread::Init() { IPC::Channel::MODE_CLIENT, this, NULL, owner_loop_, true, RenderProcess::GetShutDownEvent())); - tls_index_.Set(this); + ThreadLocalStorage::Set(tls_index_, this); // The renderer thread should wind-up COM. CoInitialize(0); diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h index 5e4f336..9463a20 100644 --- a/chrome/renderer/render_thread.h +++ b/chrome/renderer/render_thread.h @@ -74,7 +74,7 @@ class RenderThread : public IPC::Channel::Listener, // The RenderThread instance for the current thread. static RenderThread* current() { - return static_cast<RenderThread*>(tls_index_.Get()); + return static_cast<RenderThread*>(ThreadLocalStorage::Get(tls_index_)); } VisitedLinkSlave* visited_link_slave() const { return visited_link_slave_; } @@ -119,7 +119,7 @@ class RenderThread : public IPC::Channel::Listener, // decisions about how to allocation resources using current information. void InformHostOfCacheStats(); - static TLSSlot tls_index_; + static DWORD tls_index_; // The message loop used to run tasks on the thread that started this thread. MessageLoop* owner_loop_; |