int ThreadId::GetCurrentThreadId() {
- Isolate::EnsureInitialized();
int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_);
if (thread_id == 0) {
thread_id = AllocateThreadId();
#ifdef DEBUG
base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key;
#endif // DEBUG
-base::LazyMutex Isolate::process_wide_mutex_ = LAZY_MUTEX_INITIALIZER;
+base::Mutex Isolate::process_wide_mutex_;
+// TODO(dcarney): Remove with default isolate.
+enum DefaultIsolateStatus {
+ kDefaultIsolateUninitialized,
+ kDefaultIsolateInitialized,
+ kDefaultIsolateCrashIfInitialized
+};
+static DefaultIsolateStatus default_isolate_status_
+ = kDefaultIsolateUninitialized;
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_.Pointer());
+ base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
per_thread = thread_data_table_->Lookup(this, thread_id);
if (per_thread == NULL) {
per_thread = new PerIsolateThreadData(this, thread_id);
Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread(
ThreadId thread_id) {
- EnsureInitialized();
PerIsolateThreadData* per_thread = NULL;
{
- base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
+ base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
per_thread = thread_data_table_->Lookup(this, thread_id);
}
return per_thread;
}
-void Isolate::EnsureInitialized() {
- base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
+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);
if (thread_data_table_ == NULL) {
isolate_key_ = base::Thread::CreateThreadLocalKey();
thread_id_key_ = base::Thread::CreateThreadLocalKey();
}
}
+struct StaticInitializer {
+ StaticInitializer() {
+ Isolate::EnsureDefaultIsolate();
+ }
+} static_initializer;
+
Address Isolate::get_address_from_id(Isolate::AddressId id) {
return isolate_addresses_[id];
Deinit();
- { base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
+ { base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
thread_data_table_->RemoveAllThreads(this);
}
void Isolate::SetIsolateThreadLocals(Isolate* isolate,
PerIsolateThreadData* data) {
- EnsureInitialized();
base::Thread::SetThreadLocal(isolate_key_, isolate);
base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
}
static void GlobalTearDown();
+ static void SetCrashIfDefaultIsolateInitialized();
+ // Ensures that process-wide resources and the default isolate have been
+ // allocated. It is only necessary to call this method in rare cases, for
+ // example if you are using V8 from within the body of a static initializer.
+ // Safe to call multiple times.
+ static void EnsureDefaultIsolate();
+
// Find the PerThread for this particular (isolate, thread) combination
// If one does not yet exist, return null.
PerIsolateThreadData* FindPerThreadDataForThisThread();
void CountUsage(v8::Isolate::UseCounterFeature feature);
private:
- static void EnsureInitialized();
-
Isolate();
friend struct GlobalState;
};
// This mutex protects highest_thread_id_ and thread_data_table_.
- static base::LazyMutex process_wide_mutex_;
+ static base::Mutex process_wide_mutex_;
static base::Thread::LocalStorageKey per_isolate_thread_data_key_;
static base::Thread::LocalStorageKey isolate_key_;