Browse Source

thread rename for ios and osx (if called from the thread to be renamed)

Ariel Manzur 9 years ago
parent
commit
4a7e5fafb1
3 changed files with 20 additions and 1 deletions
  1. 17 1
      drivers/unix/thread_posix.cpp
  2. 2 0
      platform/iphone/platform_config.h
  3. 1 0
      platform/osx/platform_config.h

+ 17 - 1
drivers/unix/thread_posix.cpp

@@ -45,8 +45,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;
 }
 
@@ -81,8 +81,24 @@ Error ThreadPosix::set_name(const String& p_name) {
 
 	ERR_FAIL_COND_V(pthread == 0, ERR_UNCONFIGURED);
 
+	#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
+
 	int err = pthread_setname_np(pthread, p_name.utf8().get_data());
 
+	#endif
+
 	return err == 0 ? OK : ERR_INVALID_PARAMETER;
 };
 

+ 2 - 0
platform/iphone/platform_config.h

@@ -31,3 +31,5 @@
 
 
 #define PLATFORM_REFCOUNT
+
+#define PTHREAD_RENAME_SELF

+ 1 - 0
platform/osx/platform_config.h

@@ -29,3 +29,4 @@
 #include <alloca.h>
 #define GLES2_INCLUDE_H "gl_context/glew.h"
 #define GLES1_INCLUDE_H "gl_context/glew.h"
+#define PTHREAD_RENAME_SELF