Przeglądaj źródła

fixes osx/ios set thread name (#284)

actboy168 1 rok temu
rodzic
commit
98c43d8765
2 zmienionych plików z 11 dodań i 5 usunięć
  1. 1 0
      include/bx/thread.h
  2. 10 5
      src/thread.cpp

+ 1 - 0
include/bx/thread.h

@@ -72,6 +72,7 @@ namespace bx
 		uint32_t  m_stackSize;
 		int32_t   m_exitCode;
 		bool      m_running;
+		char      m_name[32];
 	};
 
 	///

+ 10 - 5
src/thread.cpp

@@ -132,6 +132,15 @@ namespace bx
 		m_userData = _userData;
 		m_stackSize = _stackSize;
 
+        if (NULL != _name)
+        {
+            strCopy(m_name, sizeof(m_name), _name);
+        }
+        else
+        {
+            m_name[0] = '\0';
+        }
+
 		ThreadInternal* ti = (ThreadInternal*)m_internal;
 #if BX_CRT_NONE
 		ti->m_handle = crt0::threadCreate(&ti->threadFunc, _userData, m_stackSize, _name);
@@ -190,11 +199,6 @@ namespace bx
 		m_running = true;
 		m_sem.wait();
 
-		if (NULL != _name)
-		{
-			setThreadName(_name);
-		}
-
 		return true;
 	}
 
@@ -316,6 +320,7 @@ namespace bx
 #endif // BX_PLATFORM_WINDOWS
 
 		m_sem.post();
+		setThreadName(m_name);
 		int32_t result = m_fn(this, m_userData);
 		return result;
 	}