Commit 30b43a8a authored by jochen's avatar jochen Committed by Commit bot

Document that Isolate::GetCurrent() must not be called before initialization

Also, add a check for debug mode.

BUG=none
R=dcarney@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/758043002

Cr-Commit-Position: refs/heads/master@{#25507}
parent a01f4d87
......@@ -4650,6 +4650,8 @@ class V8_EXPORT Isolate {
/**
* Returns the entered isolate for the current thread or NULL in
* case there is no current isolate.
*
* This method must not be invoked before V8::Initialize() was invoked.
*/
static Isolate* GetCurrent();
......
......@@ -118,6 +118,9 @@ base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
base::LazyMutex Isolate::thread_data_table_mutex_ = LAZY_MUTEX_INITIALIZER;
Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
base::Atomic32 Isolate::isolate_counter_ = 0;
#if DEBUG
base::Atomic32 Isolate::isolate_key_created_ = 0;
#endif
Isolate::PerIsolateThreadData*
Isolate::FindOrAllocatePerThreadDataForThisThread() {
......@@ -157,6 +160,9 @@ void Isolate::InitializeOncePerProcess() {
base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer());
CHECK(thread_data_table_ == NULL);
isolate_key_ = base::Thread::CreateThreadLocalKey();
#if DEBUG
base::NoBarrier_Store(&isolate_key_created_, 1);
#endif
thread_id_key_ = base::Thread::CreateThreadLocalKey();
per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey();
thread_data_table_ = new Isolate::ThreadDataTable();
......
......@@ -486,6 +486,7 @@ class Isolate {
// Returns the isolate inside which the current thread is running.
INLINE(static Isolate* Current()) {
DCHECK(base::NoBarrier_Load(&isolate_key_created_) == 1);
Isolate* isolate = reinterpret_cast<Isolate*>(
base::Thread::GetExistingThreadLocal(isolate_key_));
DCHECK(isolate != NULL);
......@@ -493,6 +494,7 @@ class Isolate {
}
INLINE(static Isolate* UncheckedCurrent()) {
DCHECK(base::NoBarrier_Load(&isolate_key_created_) == 1);
return reinterpret_cast<Isolate*>(
base::Thread::GetThreadLocal(isolate_key_));
}
......@@ -1177,6 +1179,10 @@ class Isolate {
// A global counter for all generated Isolates, might overflow.
static base::Atomic32 isolate_counter_;
#if DEBUG
static base::Atomic32 isolate_key_created_;
#endif
void Deinit();
static void SetIsolateThreadLocals(Isolate* isolate,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment