Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make fibers work on v18 #2

Open
wants to merge 1 commit into
base: v18.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading