diff options
Diffstat (limited to 'drivers/unix/thread_posix.cpp')
-rw-r--r-- | drivers/unix/thread_posix.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/drivers/unix/thread_posix.cpp b/drivers/unix/thread_posix.cpp index 03963a9756..bd33c81298 100644 --- a/drivers/unix/thread_posix.cpp +++ b/drivers/unix/thread_posix.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -30,6 +30,10 @@ #if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED) +#ifdef PTHREAD_BSD_SET_NAME +#include <pthread_np.h> +#endif + #include "os/memory.h" Thread::ID ThreadPosix::get_ID() const { @@ -45,8 +49,8 @@ Thread* ThreadPosix::create_thread_posix() { void *ThreadPosix::thread_callback(void *userdata) { ThreadPosix *t=reinterpret_cast<ThreadPosix*>(userdata); - t->callback(t->user); t->id=(ID)pthread_self(); + t->callback(t->user); return NULL; } @@ -77,6 +81,42 @@ 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); + + #ifdef PTHREAD_NO_RENAME + return ERR_UNAVAILABLE; + + #else + + #ifdef PTHREAD_RENAME_SELF + + // check if thread is the same as caller + int caller = Thread::get_caller_ID(); + int self = get_ID(); + if (caller != self) { + ERR_EXPLAIN("On this platform, thread can only be renamed with calls from the threads to be renamed."); + ERR_FAIL_V(ERR_UNAVAILABLE); + return ERR_UNAVAILABLE; + }; + int err = pthread_setname_np(p_name.utf8().get_data()); + + #else + + #ifdef PTHREAD_BSD_SET_NAME + pthread_set_name_np(pthread, p_name.utf8().get_data()); + int err = 0; // Open/FreeBSD ignore errors in this function + #else + int err = pthread_setname_np(pthread, p_name.utf8().get_data()); + #endif // PTHREAD_BSD_SET_NAME + + #endif // PTHREAD_RENAME_SELF + + return err == 0 ? OK : ERR_INVALID_PARAMETER; + + #endif // PTHREAD_NO_RENAME +}; void ThreadPosix::make_default() { |