Эх сурвалжийг харах

Small improvements in Thread class.

- Make the helper functions to run the threaded function in the new thread static. This avoids
  exposing the symbol for the helper functions.
- Thread::GetCurrentThreadID() should not use pthread if ATOMIC_THREADING is undefined.
Manuel Freiberger 8 жил өмнө
parent
commit
71a1fc9295

+ 12 - 7
Source/Atomic/Core/Thread.cpp

@@ -38,6 +38,7 @@ namespace Atomic
 #ifdef ATOMIC_THREADING
 #ifdef ATOMIC_THREADING
 #ifdef _WIN32
 #ifdef _WIN32
 
 
+static
 DWORD WINAPI ThreadFunctionStatic(void* data)
 DWORD WINAPI ThreadFunctionStatic(void* data)
 {
 {
     Thread* thread = static_cast<Thread*>(data);
     Thread* thread = static_cast<Thread*>(data);
@@ -47,6 +48,7 @@ DWORD WINAPI ThreadFunctionStatic(void* data)
 
 
 #else
 #else
 
 
+static
 void* ThreadFunctionStatic(void* data)
 void* ThreadFunctionStatic(void* data)
 {
 {
     Thread* thread = static_cast<Thread*>(data);
     Thread* thread = static_cast<Thread*>(data);
@@ -56,7 +58,7 @@ void* ThreadFunctionStatic(void* data)
 }
 }
 
 
 #endif
 #endif
-#endif
+#endif // ATOMIC_THREADING
 
 
 ThreadID Thread::mainThreadID;
 ThreadID Thread::mainThreadID;
 
 
@@ -91,7 +93,7 @@ bool Thread::Run()
     return handle_ != 0;
     return handle_ != 0;
 #else
 #else
     return false;
     return false;
-#endif
+#endif // ATOMIC_THREADING
 }
 }
 
 
 void Thread::Stop()
 void Thread::Stop()
@@ -112,7 +114,7 @@ void Thread::Stop()
     delete thread;
     delete thread;
 #endif
 #endif
     handle_ = 0;
     handle_ = 0;
-#endif
+#endif // ATOMIC_THREADING
 }
 }
 
 
 void Thread::SetPriority(int priority)
 void Thread::SetPriority(int priority)
@@ -121,13 +123,12 @@ void Thread::SetPriority(int priority)
 #ifdef _WIN32
 #ifdef _WIN32
     if (handle_)
     if (handle_)
         SetThreadPriority((HANDLE)handle_, priority);
         SetThreadPriority((HANDLE)handle_, priority);
-#endif
-#if defined(__linux__) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
+#elif defined(__linux__) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
     pthread_t* thread = (pthread_t*)handle_;
     pthread_t* thread = (pthread_t*)handle_;
     if (thread)
     if (thread)
         pthread_setschedprio(*thread, priority);
         pthread_setschedprio(*thread, priority);
 #endif
 #endif
-#endif
+#endif // ATOMIC_THREADING
 }
 }
 
 
 void Thread::SetMainThread()
 void Thread::SetMainThread()
@@ -137,11 +138,15 @@ void Thread::SetMainThread()
 
 
 ThreadID Thread::GetCurrentThreadID()
 ThreadID Thread::GetCurrentThreadID()
 {
 {
+#ifdef ATOMIC_THREADING
 #ifdef _WIN32
 #ifdef _WIN32
     return GetCurrentThreadId();
     return GetCurrentThreadId();
 #else
 #else
     return pthread_self();
     return pthread_self();
 #endif
 #endif
+#else
+    return ThreadID();
+#endif // ATOMIC_THREADING
 }
 }
 
 
 bool Thread::IsMainThread()
 bool Thread::IsMainThread()
@@ -150,7 +155,7 @@ bool Thread::IsMainThread()
     return GetCurrentThreadID() == mainThreadID;
     return GetCurrentThreadID() == mainThreadID;
 #else
 #else
     return true;
     return true;
-#endif
+#endif // ATOMIC_THREADING
 }
 }
 
 
 }
 }