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

[pull] master from godotengine:master #135

Merged
merged 2 commits into from
Jan 5, 2025
Merged
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
2 changes: 1 addition & 1 deletion core/os/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#include "core/object/script_language.h"

SafeNumeric<uint64_t> Thread::id_counter(1); // The first value after .increment() is 2, hence by default the main thread ID should be 1.
thread_local Thread::ID Thread::caller_id = Thread::id_counter.increment();

thread_local Thread::ID Thread::caller_id = Thread::UNASSIGNED_ID;
#endif

Thread::PlatformFunctions Thread::platform_functions;
Expand Down
6 changes: 2 additions & 4 deletions core/os/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,22 @@ class Thread {
static PlatformFunctions platform_functions;

ID id = UNASSIGNED_ID;

static SafeNumeric<uint64_t> id_counter;
static thread_local ID caller_id;
THREADING_NAMESPACE::thread thread;

static void callback(ID p_caller_id, const Settings &p_settings, Thread::Callback p_callback, void *p_userdata);

static void make_main_thread() { caller_id = MAIN_ID; }
static void release_main_thread() { caller_id = UNASSIGNED_ID; }
static void release_main_thread() { caller_id = id_counter.increment(); }

public:
static void _set_platform_functions(const PlatformFunctions &p_functions);

_FORCE_INLINE_ ID get_id() const { return id; }
// get the ID of the caller thread
_FORCE_INLINE_ static ID get_caller_id() {
if (unlikely(caller_id == UNASSIGNED_ID)) {
caller_id = id_counter.increment();
}
return caller_id;
}
// get the ID of the main thread
Expand Down