Skip to content

Commit

Permalink
revert v8/v8@dacc2fe
Browse files Browse the repository at this point in the history
  • Loading branch information
seanwentzel committed Jan 5, 2024
1 parent 9e0c715 commit 787f44c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions deps/v8/src/base/platform/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,13 @@ class V8_BASE_EXPORT Thread {
static LocalStorageKey CreateThreadLocalKey();
static void DeleteThreadLocalKey(LocalStorageKey key);
static void* GetThreadLocal(LocalStorageKey key);
static int GetThreadLocalInt(LocalStorageKey key) {
return static_cast<int>(reinterpret_cast<intptr_t>(GetThreadLocal(key)));
}
static void SetThreadLocal(LocalStorageKey key, void* value);
static void SetThreadLocalInt(LocalStorageKey key, int value) {
SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value)));
}
static bool HasThreadLocal(LocalStorageKey key) {
return GetThreadLocal(key) != nullptr;
}
Expand Down
7 changes: 6 additions & 1 deletion deps/v8/src/execution/thread-id.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@ namespace internal {

namespace {

thread_local int thread_id = 0;
DEFINE_LAZY_LEAKY_OBJECT_GETTER(base::Thread::LocalStorageKey, GetThreadIdKey,
base::Thread::CreateThreadLocalKey())

std::atomic<int> next_thread_id{1};

} // namespace

// static
ThreadId ThreadId::TryGetCurrent() {
int thread_id = base::Thread::GetThreadLocalInt(*GetThreadIdKey());
return thread_id == 0 ? Invalid() : ThreadId(thread_id);
}

// static
int ThreadId::GetCurrentThreadId() {
auto key = *GetThreadIdKey();
int thread_id = base::Thread::GetThreadLocalInt(key);
if (thread_id == 0) {
thread_id = next_thread_id.fetch_add(1);
CHECK_LE(1, thread_id);
base::Thread::SetThreadLocalInt(key, thread_id);
}
return thread_id;
}
Expand Down

0 comments on commit 787f44c

Please sign in to comment.