|
@@ -17,7 +17,7 @@ namespace Common
|
|
|
|
|
|
|
|
int CurrentThreadId()
|
|
int CurrentThreadId()
|
|
|
{
|
|
{
|
|
|
-#ifdef _WIN32
|
|
|
|
|
|
|
+#ifdef MSVC_VER
|
|
|
return GetCurrentThreadId();
|
|
return GetCurrentThreadId();
|
|
|
#elif defined __APPLE__
|
|
#elif defined __APPLE__
|
|
|
return mach_thread_self();
|
|
return mach_thread_self();
|
|
@@ -27,6 +27,14 @@ int CurrentThreadId()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
#ifdef _WIN32
|
|
|
|
|
+// Supporting functions
|
|
|
|
|
+void SleepCurrentThread(int ms)
|
|
|
|
|
+{
|
|
|
|
|
+ Sleep(ms);
|
|
|
|
|
+}
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+#ifdef MSVC_VER
|
|
|
|
|
|
|
|
void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask)
|
|
void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask)
|
|
|
{
|
|
{
|
|
@@ -38,12 +46,6 @@ void SetCurrentThreadAffinity(u32 mask)
|
|
|
SetThreadAffinityMask(GetCurrentThread(), mask);
|
|
SetThreadAffinityMask(GetCurrentThread(), mask);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Supporting functions
|
|
|
|
|
-void SleepCurrentThread(int ms)
|
|
|
|
|
-{
|
|
|
|
|
- Sleep(ms);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
void SwitchCurrentThread()
|
|
void SwitchCurrentThread()
|
|
|
{
|
|
{
|
|
|
SwitchToThread();
|
|
SwitchToThread();
|
|
@@ -82,7 +84,7 @@ void SetCurrentThreadName(const char* szThreadName)
|
|
|
{}
|
|
{}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#else // !WIN32, so must be POSIX threads
|
|
|
|
|
|
|
+#else // !MSVC_VER, so must be POSIX threads
|
|
|
|
|
|
|
|
void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask)
|
|
void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask)
|
|
|
{
|
|
{
|
|
@@ -106,6 +108,7 @@ void SetCurrentThreadAffinity(u32 mask)
|
|
|
SetThreadAffinity(pthread_self(), mask);
|
|
SetThreadAffinity(pthread_self(), mask);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#ifndef _WIN32
|
|
|
void SleepCurrentThread(int ms)
|
|
void SleepCurrentThread(int ms)
|
|
|
{
|
|
{
|
|
|
usleep(1000 * ms);
|
|
usleep(1000 * ms);
|
|
@@ -115,7 +118,10 @@ void SwitchCurrentThread()
|
|
|
{
|
|
{
|
|
|
usleep(1000 * 1);
|
|
usleep(1000 * 1);
|
|
|
}
|
|
}
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|
+// MinGW with the POSIX threading model does not support pthread_setname_np
|
|
|
|
|
+#if !defined(_WIN32) || defined(MSVC_VER)
|
|
|
void SetCurrentThreadName(const char* szThreadName)
|
|
void SetCurrentThreadName(const char* szThreadName)
|
|
|
{
|
|
{
|
|
|
#ifdef __APPLE__
|
|
#ifdef __APPLE__
|
|
@@ -126,6 +132,7 @@ void SetCurrentThreadName(const char* szThreadName)
|
|
|
pthread_setname_np(pthread_self(), szThreadName);
|
|
pthread_setname_np(pthread_self(), szThreadName);
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|