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

Unified Diff: chrome/common/ipc_sync_channel.cc

Issue 1660: Move a bunch of code from the old to new TLS interface. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/thread.cc ('k') | chrome/common/notification_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/ipc_sync_channel.cc
===================================================================
--- chrome/common/ipc_sync_channel.cc (revision 1894)
+++ chrome/common/ipc_sync_channel.cc (working copy)
@@ -6,8 +6,9 @@
#include "chrome/common/ipc_sync_channel.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
-#include "base/thread_local_storage.h"
+#include "base/thread_local.h"
#include "chrome/common/child_process.h"
#include "chrome/common/ipc_logging.h"
#include "chrome/common/ipc_sync_message.h"
@@ -31,9 +32,7 @@
// SyncChannel objects on the same thread (since one object can receive a
// 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;
+class SyncChannel::ReceivedSyncMsgQueue;
class SyncChannel::ReceivedSyncMsgQueue :
public base::RefCountedThreadSafe<ReceivedSyncMsgQueue> {
@@ -45,10 +44,10 @@
}
~ReceivedSyncMsgQueue() {
- DCHECK(g_tls_index.Get());
+ DCHECK(lazy_tls_ptr_.Pointer()->Get());
DCHECK(MessageLoop::current() == listener_message_loop_);
CloseHandle(blocking_event_);
- g_tls_index.Set(NULL);
+ lazy_tls_ptr_.Pointer()->Set(NULL);
}
// Called on IPC thread when a synchronous message or reply arrives.
@@ -155,6 +154,10 @@
HANDLE blocking_event() { return blocking_event_; }
MessageLoop* listener_message_loop() { return listener_message_loop_; }
+ // Holds a pointer to the per-thread ReceivedSyncMsgQueue object.
+ static base::LazyInstance<base::ThreadLocalPointer<ReceivedSyncMsgQueue> >
+ lazy_tls_ptr_;
+
private:
// Called on the ipc thread to check if we can unblock any current Send()
// calls based on a queued reply.
@@ -203,6 +206,8 @@
std::vector<Reply> received_replies_;
};
+base::LazyInstance<base::ThreadLocalPointer<SyncChannel::ReceivedSyncMsgQueue> >
+ SyncChannel::ReceivedSyncMsgQueue::lazy_tls_ptr_(base::LINKER_INITIALIZED);
SyncChannel::SyncContext::SyncContext(
Channel::Listener* listener,
@@ -213,13 +218,13 @@
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_ = ReceivedSyncMsgQueue::lazy_tls_ptr_.Pointer()->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();
- g_tls_index.Set(received_sync_msgs_);
+ ReceivedSyncMsgQueue::lazy_tls_ptr_.Pointer()->Set(received_sync_msgs_);
}
// Addref manually so that we can ensure destruction on the listener thread
« no previous file with comments | « base/thread.cc ('k') | chrome/common/notification_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698