Branimir Karadžić 10 anni fa
parent
commit
11bae63fe1
1 ha cambiato i file con 19 aggiunte e 12 eliminazioni
  1. 19 12
      include/bx/thread.h

+ 19 - 12
include/bx/thread.h

@@ -31,8 +31,9 @@ namespace bx
 
 
 	public:
 	public:
 		Thread()
 		Thread()
-#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT
+#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT
 			: m_handle(INVALID_HANDLE_VALUE)
 			: m_handle(INVALID_HANDLE_VALUE)
+			, m_threadId(UINT32_MAX)
 #elif BX_PLATFORM_POSIX
 #elif BX_PLATFORM_POSIX
 			: m_handle(0)
 			: m_handle(0)
 #endif // BX_PLATFORM_
 #endif // BX_PLATFORM_
@@ -61,7 +62,7 @@ namespace bx
 			m_stackSize = _stackSize;
 			m_stackSize = _stackSize;
 			m_running = true;
 			m_running = true;
 
 
-#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360
+#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
 			m_handle = CreateThread(NULL
 			m_handle = CreateThread(NULL
 				, m_stackSize
 				, m_stackSize
 				, threadFunc
 				, threadFunc
@@ -101,17 +102,18 @@ namespace bx
 			BX_CHECK(0 == result, "pthread_attr_setschedparam failed! %d", result);
 			BX_CHECK(0 == result, "pthread_attr_setschedparam failed! %d", result);
 #endif // BX_PLATFORM_
 #endif // BX_PLATFORM_
 
 
+			m_sem.wait();
+
 			if (NULL != _name)
 			if (NULL != _name)
 			{
 			{
 				setThreadName(_name);
 				setThreadName(_name);
 			}
 			}
-			m_sem.wait();
 		}
 		}
 
 
 		void shutdown()
 		void shutdown()
 		{
 		{
 			BX_CHECK(m_running, "Not running!");
 			BX_CHECK(m_running, "Not running!");
-#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360
+#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
 			WaitForSingleObject(m_handle, INFINITE);
 			WaitForSingleObject(m_handle, INFINITE);
 			GetExitCodeThread(m_handle, (DWORD*)&m_exitCode);
 			GetExitCodeThread(m_handle, (DWORD*)&m_exitCode);
 			CloseHandle(m_handle);
 			CloseHandle(m_handle);
@@ -162,7 +164,7 @@ namespace bx
 			ThreadName tn;
 			ThreadName tn;
 			tn.type  = 0x1000;
 			tn.type  = 0x1000;
 			tn.name  = _name;
 			tn.name  = _name;
-			tn.id    = GetThreadId(m_handle);
+			tn.id    = m_threadId;
 			tn.flags = 0;
 			tn.flags = 0;
 
 
 			__try
 			__try
@@ -184,11 +186,15 @@ namespace bx
 	private:
 	private:
 		int32_t entry()
 		int32_t entry()
 		{
 		{
+#if BX_PLATFORM_WINDOWS
+			m_threadId = ::GetCurrentThreadId();
+#endif // BX_PLATFORM_WINDOWS
+
 			m_sem.post();
 			m_sem.post();
 			return m_fn(m_userData);
 			return m_fn(m_userData);
 		}
 		}
 
 
-#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT
+#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT
 		static DWORD WINAPI threadFunc(LPVOID _arg)
 		static DWORD WINAPI threadFunc(LPVOID _arg)
 		{
 		{
 			Thread* thread = (Thread*)_arg;
 			Thread* thread = (Thread*)_arg;
@@ -209,18 +215,19 @@ namespace bx
 		}
 		}
 #endif // BX_PLATFORM_
 #endif // BX_PLATFORM_
 
 
-#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT
+#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT
 		HANDLE m_handle;
 		HANDLE m_handle;
+		DWORD  m_threadId;
 #elif BX_PLATFORM_POSIX
 #elif BX_PLATFORM_POSIX
 		pthread_t m_handle;
 		pthread_t m_handle;
 #endif // BX_PLATFORM_
 #endif // BX_PLATFORM_
 
 
-		ThreadFn m_fn;
-		void* m_userData;
+		ThreadFn  m_fn;
+		void*     m_userData;
 		Semaphore m_sem;
 		Semaphore m_sem;
-		uint32_t m_stackSize;
-		int32_t m_exitCode;
-		bool m_running;
+		uint32_t  m_stackSize;
+		int32_t   m_exitCode;
+		bool      m_running;
 	};
 	};
 
 
 #if BX_PLATFORM_WINDOWS
 #if BX_PLATFORM_WINDOWS