thread set name

This commit is contained in:
Ariel Manzur 2015-12-17 06:24:27 -03:00
parent 6c3c20fc35
commit 10298b9534
7 changed files with 35 additions and 1 deletions

View File

@ -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 );

View File

@ -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();

View File

@ -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()
{
}

View File

@ -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;

View File

@ -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() {

View File

@ -61,6 +61,7 @@ public:
virtual ID get_ID() const;
Error set_name(const String& p_name);
static void make_default();

View File

@ -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
}