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

Unified Diff: base/threading/thread_local_storage.cc

Issue 2667513003: Remove some LazyInstance use in base/ (Closed)
Patch Set: no message_window Created 3 years, 11 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
Index: base/threading/thread_local_storage.cc
diff --git a/base/threading/thread_local_storage.cc b/base/threading/thread_local_storage.cc
index 15a1d5e2dbb498ea0c7b18f294b1805a7bbfe8dd..198a308a659de9708576001ef29b96c13380fce6 100644
--- a/base/threading/thread_local_storage.cc
+++ b/base/threading/thread_local_storage.cc
@@ -5,7 +5,6 @@
#include "base/threading/thread_local_storage.h"
#include "base/atomicops.h"
-#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/synchronization/lock.h"
#include "build/build_config.h"
@@ -90,9 +89,12 @@ struct TlsVectorEntry {
uint32_t version;
};
-// This LazyInstance isn't needed until after we've constructed the per-thread
-// TLS vector, so it's safe to use.
-base::LazyInstance<base::Lock>::Leaky g_tls_metadata_lock;
+// This lock isn't needed until after we've constructed the per-thread TLS
+// vector, so it's safe to use.
+base::Lock* GetTLSMetadataLock() {
+ static auto lock = new base::Lock();
+ return lock;
+}
TlsMetadata g_tls_metadata[kThreadLocalStorageSize];
size_t g_last_assigned_slot = 0;
@@ -182,7 +184,7 @@ void OnThreadExitInternal(TlsVectorEntry* tls_data) {
// Snapshot the TLS Metadata so we don't have to lock on every access.
TlsMetadata tls_metadata[kThreadLocalStorageSize];
{
- base::AutoLock auto_lock(g_tls_metadata_lock.Get());
+ base::AutoLock auto_lock(*GetTLSMetadataLock());
memcpy(tls_metadata, g_tls_metadata, sizeof(g_tls_metadata));
}
@@ -261,7 +263,7 @@ void ThreadLocalStorage::StaticSlot::Initialize(TLSDestructorFunc destructor) {
slot_ = kInvalidSlotValue;
version_ = 0;
{
- base::AutoLock auto_lock(g_tls_metadata_lock.Get());
+ base::AutoLock auto_lock(*GetTLSMetadataLock());
for (int i = 0; i < kThreadLocalStorageSize; ++i) {
// Tracking the last assigned slot is an attempt to find the next
// available slot within one iteration. Under normal usage, slots remain
@@ -291,7 +293,7 @@ void ThreadLocalStorage::StaticSlot::Free() {
DCHECK_NE(slot_, kInvalidSlotValue);
DCHECK_LT(slot_, kThreadLocalStorageSize);
{
- base::AutoLock auto_lock(g_tls_metadata_lock.Get());
+ base::AutoLock auto_lock(*GetTLSMetadataLock());
g_tls_metadata[slot_].status = TlsStatus::FREE;
g_tls_metadata[slot_].destructor = nullptr;
++(g_tls_metadata[slot_].version);
« no previous file with comments | « base/path_service.cc ('k') | base/threading/watchdog.cc » ('j') | base/trace_event/trace_log.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698