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

Unified Diff: src/isolate.cc

Issue 9455088: Remove static initializers in v8. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Lint. Created 8 years, 10 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: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 128136faa0b83d47ba0ed90fa972cf04282e1d2f..4247b6ccba4ceff5131d6f806ef3779e00e71a18 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -41,6 +41,7 @@
#include "lithium-allocator.h"
#include "log.h"
#include "messages.h"
+#include "platform.h"
#include "regexp-stack.h"
#include "runtime-profiler.h"
#include "scopeinfo.h"
@@ -64,10 +65,10 @@ int ThreadId::AllocateThreadId() {
int ThreadId::GetCurrentThreadId() {
- int thread_id = Thread::GetThreadLocalInt(Isolate::thread_id_key_);
+ int thread_id = Thread::GetThreadLocalInt(Isolate::thread_id_key());
if (thread_id == 0) {
thread_id = AllocateThreadId();
- Thread::SetThreadLocalInt(Isolate::thread_id_key_, thread_id);
+ Thread::SetThreadLocalInt(Isolate::thread_id_key(), thread_id);
}
return thread_id;
}
@@ -312,43 +313,26 @@ void Isolate::PreallocatedStorageDelete(void* p) {
}
+// This mutex protects highest_thread_id_, thread_data_table_ and
+// g_default_mutex_.
+static LazyMutex process_wide_mutex = LAZY_MUTEX_INITIALIZER;
+
Isolate* Isolate::default_isolate_ = NULL;
Thread::LocalStorageKey Isolate::isolate_key_;
Thread::LocalStorageKey Isolate::thread_id_key_;
Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
-Mutex* Isolate::process_wide_mutex_ = OS::CreateMutex();
Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
-class IsolateInitializer {
- public:
- IsolateInitializer() {
- Isolate::EnsureDefaultIsolate();
- }
-};
-
-static IsolateInitializer* EnsureDefaultIsolateAllocated() {
- // TODO(isolates): Use the system threading API to do this once?
- static IsolateInitializer static_initializer;
- return &static_initializer;
-}
-
-// This variable only needed to trigger static intialization.
-static IsolateInitializer* static_initializer = EnsureDefaultIsolateAllocated();
-
-
-
-
-
Isolate::PerIsolateThreadData* Isolate::AllocatePerIsolateThreadData(
ThreadId thread_id) {
ASSERT(!thread_id.Equals(ThreadId::Invalid()));
PerIsolateThreadData* per_thread = new PerIsolateThreadData(this, thread_id);
{
- ScopedLock lock(process_wide_mutex_);
- ASSERT(thread_data_table_->Lookup(this, thread_id) == NULL);
- thread_data_table_->Insert(per_thread);
- ASSERT(thread_data_table_->Lookup(this, thread_id) == per_thread);
+ ScopedLock lock(process_wide_mutex.Pointer());
+ ASSERT(thread_data_table()->Lookup(this, thread_id) == NULL);
+ thread_data_table()->Insert(per_thread);
+ ASSERT(thread_data_table()->Lookup(this, thread_id) == per_thread);
}
return per_thread;
}
@@ -359,8 +343,8 @@ Isolate::PerIsolateThreadData*
ThreadId thread_id = ThreadId::Current();
PerIsolateThreadData* per_thread = NULL;
{
- ScopedLock lock(process_wide_mutex_);
- per_thread = thread_data_table_->Lookup(this, thread_id);
+ ScopedLock lock(process_wide_mutex.Pointer());
+ per_thread = thread_data_table()->Lookup(this, thread_id);
if (per_thread == NULL) {
per_thread = AllocatePerIsolateThreadData(thread_id);
}
@@ -373,15 +357,15 @@ Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() {
ThreadId thread_id = ThreadId::Current();
PerIsolateThreadData* per_thread = NULL;
{
- ScopedLock lock(process_wide_mutex_);
- per_thread = thread_data_table_->Lookup(this, thread_id);
+ ScopedLock lock(process_wide_mutex.Pointer());
+ per_thread = thread_data_table()->Lookup(this, thread_id);
}
return per_thread;
}
void Isolate::EnsureDefaultIsolate() {
- ScopedLock lock(process_wide_mutex_);
+ ScopedLock lock(process_wide_mutex.Pointer());
if (default_isolate_ == NULL) {
isolate_key_ = Thread::CreateThreadLocalKey();
thread_id_key_ = Thread::CreateThreadLocalKey();
@@ -391,8 +375,8 @@ void Isolate::EnsureDefaultIsolate() {
}
// Can't use SetIsolateThreadLocals(default_isolate_, NULL) here
// becase a non-null thread data may be already set.
- if (Thread::GetThreadLocal(isolate_key_) == NULL) {
- Thread::SetThreadLocal(isolate_key_, default_isolate_);
+ if (Thread::GetThreadLocal(Isolate::isolate_key_) == NULL) {
+ Thread::SetThreadLocal(Isolate::isolate_key_, default_isolate_);
}
}
@@ -413,12 +397,13 @@ StackGuard* Isolate::GetDefaultIsolateStackGuard() {
void Isolate::EnterDefaultIsolate() {
EnsureDefaultIsolate();
- ASSERT(default_isolate_ != NULL);
+ Isolate* const default_isolate = default_isolate_;
+ ASSERT(default_isolate != NULL);
PerIsolateThreadData* data = CurrentPerIsolateThreadData();
// If not yet in default isolate - enter it.
- if (data == NULL || data->isolate() != default_isolate_) {
- default_isolate_->Enter();
+ if (data == NULL || data->isolate() != default_isolate) {
+ default_isolate->Enter();
}
}
@@ -1547,8 +1532,8 @@ void Isolate::TearDown() {
Deinit();
- { ScopedLock lock(process_wide_mutex_);
- thread_data_table_->RemoveAllThreads(this);
+ { ScopedLock lock(process_wide_mutex.Pointer());
+ thread_data_table()->RemoveAllThreads(this);
}
if (!IsDefaultIsolate()) {
@@ -1601,8 +1586,8 @@ void Isolate::Deinit() {
void Isolate::SetIsolateThreadLocals(Isolate* isolate,
PerIsolateThreadData* data) {
- Thread::SetThreadLocal(isolate_key_, isolate);
- Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
+ Thread::SetThreadLocal(isolate_key(), isolate);
+ Thread::SetThreadLocal(per_isolate_thread_data_key(), data);
}

Powered by Google App Engine
This is Rietveld 408576698