diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-08-29 00:07:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-29 00:07:07 +0200 |
commit | 9a8a0e20e5b73b6536c92b7b68e827e4f6d18f48 (patch) | |
tree | a9ccf069b84d7dc7f124d8880d502ab2b133f153 /drivers/unix/thread_posix.cpp | |
parent | 0f7376921f8e1d150933c3abb0474b9e8a8d14cc (diff) | |
parent | d806ad4a3dcf7308147e1a243092d22091560d7d (diff) | |
download | redot-engine-9a8a0e20e5b73b6536c92b7b68e827e4f6d18f48.tar.gz |
Merge pull request #10552 from RandomShaper/improve-posix
Improve Mac/UNIX conformance/reliability
Diffstat (limited to 'drivers/unix/thread_posix.cpp')
-rw-r--r-- | drivers/unix/thread_posix.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/drivers/unix/thread_posix.cpp b/drivers/unix/thread_posix.cpp index 2dd0b4a70a..5908246929 100644 --- a/drivers/unix/thread_posix.cpp +++ b/drivers/unix/thread_posix.cpp @@ -36,8 +36,18 @@ #include <pthread_np.h> #endif +#include "core/safe_refcount.h" #include "os/memory.h" +static pthread_key_t _create_thread_id_key() { + pthread_key_t key; + pthread_key_create(&key, NULL); + return key; +} + +pthread_key_t ThreadPosix::thread_id_key = _create_thread_id_key(); +Thread::ID ThreadPosix::next_thread_id = 0; + Thread::ID ThreadPosix::get_id() const { return id; @@ -51,7 +61,8 @@ Thread *ThreadPosix::create_thread_posix() { void *ThreadPosix::thread_callback(void *userdata) { ThreadPosix *t = reinterpret_cast<ThreadPosix *>(userdata); - t->id = (ID)pthread_self(); + t->id = atomic_increment(&next_thread_id); + pthread_setspecific(thread_id_key, (void *)t->id); ScriptServer::thread_enter(); //scripts may need to attach a stack @@ -77,7 +88,7 @@ Thread *ThreadPosix::create_func_posix(ThreadCreateCallback p_callback, void *p_ } Thread::ID ThreadPosix::get_thread_id_func_posix() { - return (ID)pthread_self(); + return (ID)pthread_getspecific(thread_id_key); } void ThreadPosix::wait_to_finish_func_posix(Thread *p_thread) { |