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

Unified Diff: src/isolate.cc

Issue 365863003: Reland^2 r22105 "Remove static initializer from isolate" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 6 years, 6 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 | « src/isolate.h ('k') | src/mksnapshot.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 5c5a2da666f0e433167bd9b885df5a8224801289..8fff82a35ddde6adca5b3a50223769da71e3abca 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -46,6 +46,7 @@ int ThreadId::AllocateThreadId() {
int ThreadId::GetCurrentThreadId() {
+ Isolate::EnsureInitialized();
int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_);
if (thread_id == 0) {
thread_id = AllocateThreadId();
@@ -104,24 +105,17 @@ base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
#ifdef DEBUG
base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key;
#endif // DEBUG
-base::Mutex Isolate::process_wide_mutex_;
-// TODO(dcarney): Remove with default isolate.
-enum DefaultIsolateStatus {
- kDefaultIsolateUninitialized,
- kDefaultIsolateInitialized,
- kDefaultIsolateCrashIfInitialized
-};
-static DefaultIsolateStatus default_isolate_status_
- = kDefaultIsolateUninitialized;
+base::LazyMutex Isolate::process_wide_mutex_ = LAZY_MUTEX_INITIALIZER;
Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
base::Atomic32 Isolate::isolate_counter_ = 0;
Isolate::PerIsolateThreadData*
Isolate::FindOrAllocatePerThreadDataForThisThread() {
+ EnsureInitialized();
ThreadId thread_id = ThreadId::Current();
PerIsolateThreadData* per_thread = NULL;
{
- base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
+ base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
per_thread = thread_data_table_->Lookup(this, thread_id);
if (per_thread == NULL) {
per_thread = new PerIsolateThreadData(this, thread_id);
@@ -141,25 +135,18 @@ Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() {
Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread(
ThreadId thread_id) {
+ EnsureInitialized();
PerIsolateThreadData* per_thread = NULL;
{
- base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
+ base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
per_thread = thread_data_table_->Lookup(this, thread_id);
}
return per_thread;
}
-void Isolate::SetCrashIfDefaultIsolateInitialized() {
- base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
- CHECK(default_isolate_status_ != kDefaultIsolateInitialized);
- default_isolate_status_ = kDefaultIsolateCrashIfInitialized;
-}
-
-
-void Isolate::EnsureDefaultIsolate() {
- base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
- CHECK(default_isolate_status_ != kDefaultIsolateCrashIfInitialized);
+void Isolate::EnsureInitialized() {
+ base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
if (thread_data_table_ == NULL) {
isolate_key_ = base::Thread::CreateThreadLocalKey();
thread_id_key_ = base::Thread::CreateThreadLocalKey();
@@ -172,12 +159,6 @@ void Isolate::EnsureDefaultIsolate() {
}
}
-struct StaticInitializer {
- StaticInitializer() {
- Isolate::EnsureDefaultIsolate();
- }
-} static_initializer;
-
Address Isolate::get_address_from_id(Isolate::AddressId id) {
return isolate_addresses_[id];
@@ -1526,7 +1507,7 @@ void Isolate::TearDown() {
Deinit();
- { base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
+ { base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
thread_data_table_->RemoveAllThreads(this);
}
@@ -1627,6 +1608,7 @@ void Isolate::PushToPartialSnapshotCache(Object* obj) {
void Isolate::SetIsolateThreadLocals(Isolate* isolate,
PerIsolateThreadData* data) {
+ EnsureInitialized();
base::Thread::SetThreadLocal(isolate_key_, isolate);
base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
}
« no previous file with comments | « src/isolate.h ('k') | src/mksnapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698