summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-20 22:54:52 +0000
committerevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-20 22:54:52 +0000
commit6a6e657234868ad4044b03bdeb9c6f7e872b5ee6 (patch)
tree36d9855863e1cf5615b62623b2347ec494447cdb /chrome
parent15e8abe105f4c2a08cd5dc51e95ec1791ac440f2 (diff)
downloadchromium_src-6a6e657234868ad4044b03bdeb9c6f7e872b5ee6.zip
chromium_src-6a6e657234868ad4044b03bdeb9c6f7e872b5ee6.tar.gz
chromium_src-6a6e657234868ad4044b03bdeb9c6f7e872b5ee6.tar.bz2
TrackedObjects assumes you can use a "TLS slot" of -1 to indicate uninitialized. This isn't true for the pthread_key_t type, which is unsigned on Linux and reportedly a struct on Macs. This change modifies the Slot type to be a struct containing an "initialized" flag.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1122 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/common/ipc_sync_channel.cc12
-rw-r--r--chrome/common/notification_service.cc10
-rw-r--r--chrome/common/notification_service.h7
-rw-r--r--chrome/common/rand_util.cc7
-rw-r--r--chrome/renderer/render_thread.cc8
-rw-r--r--chrome/renderer/render_thread.h4
6 files changed, 25 insertions, 23 deletions
diff --git a/chrome/common/ipc_sync_channel.cc b/chrome/common/ipc_sync_channel.cc
index 25a22c8..3932c6d 100644
--- a/chrome/common/ipc_sync_channel.cc
+++ b/chrome/common/ipc_sync_channel.cc
@@ -57,7 +57,8 @@ namespace IPC {
// sync message while another one is blocked).
// Holds a pointer to the per-thread ReceivedSyncMsgQueue object.
-static int g_tls_index = ThreadLocalStorage::Alloc();
+// TODO(evanm): this shouldn't rely on static initialization.
+static TLSSlot g_tls_index;
class SyncChannel::ReceivedSyncMsgQueue :
public base::RefCountedThreadSafe<ReceivedSyncMsgQueue> {
@@ -69,10 +70,10 @@ class SyncChannel::ReceivedSyncMsgQueue :
}
~ReceivedSyncMsgQueue() {
- DCHECK(ThreadLocalStorage::Get(g_tls_index));
+ DCHECK(g_tls_index.Get());
DCHECK(MessageLoop::current() == listener_message_loop_);
CloseHandle(blocking_event_);
- ThreadLocalStorage::Set(g_tls_index, NULL);
+ g_tls_index.Set(NULL);
}
// Called on IPC thread when a synchronous message or reply arrives.
@@ -237,14 +238,13 @@ 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*>(
- ThreadLocalStorage::Get(g_tls_index));
+ received_sync_msgs_ = static_cast<ReceivedSyncMsgQueue*>(g_tls_index.Get());
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();
- ThreadLocalStorage::Set(g_tls_index, received_sync_msgs_);
+ g_tls_index.Set(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 672052f..2345ba0 100644
--- a/chrome/common/notification_service.cc
+++ b/chrome/common/notification_service.cc
@@ -29,9 +29,11 @@
#include "chrome/common/notification_service.h"
-int NotificationService::tls_index_ = ThreadLocalStorage::Alloc();
+// TODO(evanm): This shouldn't depend on static initialization.
+// static
+TLSSlot NotificationService::tls_index_;
-/* static */
+// static
bool NotificationService::HasKey(const NotificationSourceMap& map,
const NotificationSource& source) {
return map.find(source.map_key()) != map.end();
@@ -43,7 +45,7 @@ NotificationService::NotificationService() {
memset(observer_counts_, 0, sizeof(observer_counts_));
#endif
- ThreadLocalStorage::Set(tls_index_, this);
+ tls_index_.Set(this);
}
void NotificationService::AddObserver(NotificationObserver* observer,
@@ -117,7 +119,7 @@ void NotificationService::Notify(NotificationType type,
NotificationService::~NotificationService() {
- ThreadLocalStorage::Set(tls_index_, NULL);
+ tls_index_.Set(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 1243748..6ad58d0 100644
--- a/chrome/common/notification_service.h
+++ b/chrome/common/notification_service.h
@@ -36,8 +36,8 @@
#include <map>
-#include "base/thread_local_storage.h"
#include "base/observer_list.h"
+#include "base/thread_local_storage.h"
#include "base/values.h"
#include "chrome/common/notification_details.h"
#include "chrome/common/notification_source.h"
@@ -50,8 +50,7 @@ class NotificationService {
// Returns the NotificationService object for the current thread, or NULL if
// none.
static NotificationService* current() {
- return static_cast<NotificationService *>(
- ThreadLocalStorage::Get(tls_index_));
+ return static_cast<NotificationService *>(tls_index_.Get());
}
// Normally instantiated when the thread is created. Not all threads have
@@ -119,7 +118,7 @@ class NotificationService {
// The thread local storage index, used for getting the current thread's
// instance.
- static int tls_index_;
+ static TLSSlot 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 13c586f..d6c2824 100644
--- a/chrome/common/rand_util.cc
+++ b/chrome/common/rand_util.cc
@@ -39,12 +39,13 @@
namespace rand_util {
+// TODO(evanm): don't rely on static initialization.
// Using TLS since srand() needs to be called once in each thread.
-int g_tls_index = ThreadLocalStorage::Alloc();
+TLSSlot g_tls_index;
int RandInt(int min, int max) {
- if (ThreadLocalStorage::Get(g_tls_index) == 0) {
- ThreadLocalStorage::Set(g_tls_index, reinterpret_cast<void*>(1));
+ if (g_tls_index.Get() == 0) {
+ g_tls_index.Set(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 b37cf454..14f9313 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -47,8 +47,9 @@ static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */;
// V8 needs a 1MB stack size.
static const size_t kStackSize = 1024 * 1024;
-/*static*/
-DWORD RenderThread::tls_index_ = ThreadLocalStorage::Alloc();
+// TODO(evanm): don't rely on static initialization.
+// static
+TLSSlot RenderThread::tls_index_;
//-----------------------------------------------------------------------------
// Methods below are only called on the owner's thread:
@@ -106,7 +107,6 @@ 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()));
- ThreadLocalStorage::Set(tls_index_, this);
+ tls_index_.Set(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 9463a20..5e4f336 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*>(ThreadLocalStorage::Get(tls_index_));
+ return static_cast<RenderThread*>(tls_index_.Get());
}
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 DWORD tls_index_;
+ static TLSSlot tls_index_;
// The message loop used to run tasks on the thread that started this thread.
MessageLoop* owner_loop_;