summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/bind/core_bind.cpp15
-rw-r--r--core/bind/core_bind.h2
-rw-r--r--core/os/thread.cpp5
-rw-r--r--core/os/thread.h4
-rw-r--r--drivers/unix/thread_posix.cpp8
-rw-r--r--drivers/unix/thread_posix.h1
-rw-r--r--servers/audio/audio_server_sw.cpp1
7 files changed, 35 insertions, 1 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 30c90bd71c..743ae19a93 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -1941,6 +1941,9 @@ Error _Thread::start(Object *p_instance,const StringName& p_method,const Variant
return ERR_CANT_CREATE;
}
+ if (name != "")
+ thread->set_name(name);
+
return OK;
}
@@ -1972,12 +1975,24 @@ Variant _Thread::wait_to_finish() {
return r;
}
+Error _Thread::set_name(const String &p_name) {
+
+ name = p_name;
+
+ if (thread) {
+ return thread->set_name(p_name);
+ };
+
+ return OK;
+};
+
void _Thread::_bind_methods() {
ObjectTypeDB::bind_method(_MD("start:Error","instance","method","userdata","priority"),&_Thread::start,DEFVAL(Variant()),DEFVAL(PRIORITY_NORMAL));
ObjectTypeDB::bind_method(_MD("get_id"),&_Thread::get_id);
ObjectTypeDB::bind_method(_MD("is_active"),&_Thread::is_active);
ObjectTypeDB::bind_method(_MD("wait_to_finish:Variant"),&_Thread::wait_to_finish);
+ ObjectTypeDB::bind_method(_MD("set_name:Error", "name"),&_Thread::set_name);
BIND_CONSTANT( PRIORITY_LOW );
BIND_CONSTANT( PRIORITY_NORMAL );
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 24ea810767..172f33dac5 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -508,6 +508,7 @@ protected:
Object *target_instance;
StringName target_method;
Thread *thread;
+ String name;
static void _bind_methods();
static void _start_func(void *ud);
public:
@@ -523,6 +524,7 @@ public:
String get_id() const;
bool is_active() const;
Variant wait_to_finish();
+ Error set_name(const String& p_name);
_Thread();
~_Thread();
diff --git a/core/os/thread.cpp b/core/os/thread.cpp
index 96b0f561ca..53db62c176 100644
--- a/core/os/thread.cpp
+++ b/core/os/thread.cpp
@@ -58,6 +58,11 @@ void Thread::wait_to_finish(Thread *p_thread) {
}
+Error Thread::set_name(const String &p_name) {
+
+ return ERR_UNAVAILABLE;
+};
+
Thread::Thread()
{
}
diff --git a/core/os/thread.h b/core/os/thread.h
index 590fee1fc6..e3d00b0397 100644
--- a/core/os/thread.h
+++ b/core/os/thread.h
@@ -35,6 +35,7 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
+#include "ustring.h"
typedef void (*ThreadCreateCallback)(void *p_userdata);
@@ -71,7 +72,8 @@ protected:
Thread();
public:
-
+
+ virtual Error set_name(const String& p_name);
virtual ID get_ID() const=0;
diff --git a/drivers/unix/thread_posix.cpp b/drivers/unix/thread_posix.cpp
index 03963a9756..2f9adb3f6c 100644
--- a/drivers/unix/thread_posix.cpp
+++ b/drivers/unix/thread_posix.cpp
@@ -77,6 +77,14 @@ void ThreadPosix::wait_to_finish_func_posix(Thread* p_thread) {
tp->pthread=0;
}
+Error ThreadPosix::set_name(const String& p_name) {
+
+ ERR_FAIL_COND_V(pthread == 0, ERR_UNCONFIGURED);
+
+ int err = pthread_setname_np(pthread, p_name.utf8().get_data());
+
+ return err == 0 ? OK : ERR_INVALID_PARAMETER;
+};
void ThreadPosix::make_default() {
diff --git a/drivers/unix/thread_posix.h b/drivers/unix/thread_posix.h
index 4f76f3d7b3..215da444e7 100644
--- a/drivers/unix/thread_posix.h
+++ b/drivers/unix/thread_posix.h
@@ -61,6 +61,7 @@ public:
virtual ID get_ID() const;
+ Error set_name(const String& p_name);
static void make_default();
diff --git a/servers/audio/audio_server_sw.cpp b/servers/audio/audio_server_sw.cpp
index 417a582da6..d20e2d42e0 100644
--- a/servers/audio/audio_server_sw.cpp
+++ b/servers/audio/audio_server_sw.cpp
@@ -806,6 +806,7 @@ void AudioServerSW::init() {
#ifndef NO_THREADS
exit_update_thread=false;
thread = Thread::create(_thread_func,this);
+ thread->set_name("AudioServerSW");
#endif
}