Skip to content

Commit dacc2fe

Browse files
ulanCommit Bot
authored andcommitted
Use thread_local for storing ThreadId
Change-Id: Ifc754fb81089aed4cb79b1f6c4aab0cb73a2a5d7 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2537690 Reviewed-by: Igor Sheludko <ishell@chromium.org> Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#71176}
1 parent 05f41a5 commit dacc2fe

File tree

2 files changed

+1
-12
lines changed

2 files changed

+1
-12
lines changed

src/base/platform/platform.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,7 @@ class V8_BASE_EXPORT Thread {
385385
static LocalStorageKey CreateThreadLocalKey();
386386
static void DeleteThreadLocalKey(LocalStorageKey key);
387387
static void* GetThreadLocal(LocalStorageKey key);
388-
static int GetThreadLocalInt(LocalStorageKey key) {
389-
return static_cast<int>(reinterpret_cast<intptr_t>(GetThreadLocal(key)));
390-
}
391388
static void SetThreadLocal(LocalStorageKey key, void* value);
392-
static void SetThreadLocalInt(LocalStorageKey key, int value) {
393-
SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value)));
394-
}
395389
static bool HasThreadLocal(LocalStorageKey key) {
396390
return GetThreadLocal(key) != nullptr;
397391
}

src/execution/thread-id.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,22 @@ namespace internal {
1111

1212
namespace {
1313

14-
DEFINE_LAZY_LEAKY_OBJECT_GETTER(base::Thread::LocalStorageKey, GetThreadIdKey,
15-
base::Thread::CreateThreadLocalKey())
14+
thread_local int thread_id = 0;
1615

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

1918
} // namespace
2019

2120
// static
2221
ThreadId ThreadId::TryGetCurrent() {
23-
int thread_id = base::Thread::GetThreadLocalInt(*GetThreadIdKey());
2422
return thread_id == 0 ? Invalid() : ThreadId(thread_id);
2523
}
2624

2725
// static
2826
int ThreadId::GetCurrentThreadId() {
29-
auto key = *GetThreadIdKey();
30-
int thread_id = base::Thread::GetThreadLocalInt(key);
3127
if (thread_id == 0) {
3228
thread_id = next_thread_id.fetch_add(1);
3329
CHECK_LE(1, thread_id);
34-
base::Thread::SetThreadLocalInt(key, thread_id);
3530
}
3631
return thread_id;
3732
}

0 commit comments

Comments
 (0)