summaryrefslogtreecommitdiff
path: root/platform/android/thread_jandroid.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/thread_jandroid.cpp')
-rw-r--r--platform/android/thread_jandroid.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/platform/android/thread_jandroid.cpp b/platform/android/thread_jandroid.cpp
index 924ae3fe43..79488197ea 100644
--- a/platform/android/thread_jandroid.cpp
+++ b/platform/android/thread_jandroid.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -29,9 +29,19 @@
/*************************************************************************/
#include "thread_jandroid.h"
+#include "core/safe_refcount.h"
#include "os/memory.h"
#include "script_language.h"
+static pthread_key_t _create_thread_id_key() {
+ pthread_key_t key;
+ pthread_key_create(&key, NULL);
+ return key;
+}
+
+pthread_key_t ThreadAndroid::thread_id_key = _create_thread_id_key();
+Thread::ID ThreadAndroid::next_thread_id = 0;
+
Thread::ID ThreadAndroid::get_id() const {
return id;
@@ -47,7 +57,8 @@ void *ThreadAndroid::thread_callback(void *userdata) {
ThreadAndroid *t = reinterpret_cast<ThreadAndroid *>(userdata);
setup_thread();
ScriptServer::thread_enter(); //scripts may need to attach a stack
- t->id = (ID)pthread_self();
+ t->id = atomic_increment(&next_thread_id);
+ pthread_setspecific(thread_id_key, (void *)t->id);
t->callback(t->user);
ScriptServer::thread_exit();
return NULL;
@@ -68,7 +79,7 @@ Thread *ThreadAndroid::create_func_jandroid(ThreadCreateCallback p_callback, voi
Thread::ID ThreadAndroid::get_thread_id_func_jandroid() {
- return (ID)pthread_self();
+ return (ID)pthread_getspecific(thread_id_key);
}
void ThreadAndroid::wait_to_finish_func_jandroid(Thread *p_thread) {