summaryrefslogtreecommitdiff
path: root/thirdparty/etcpak/patches/pthread-setname.patch
blob: e2b009a1b370f2faaf39e697ad9064ce533c018b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
diff --git a/thirdparty/etcpak/System.cpp b/thirdparty/etcpak/System.cpp
index 1383d0ecd0..041f2676e8 100644
--- a/thirdparty/etcpak/System.cpp
+++ b/thirdparty/etcpak/System.cpp
@@ -2,7 +2,6 @@
 #ifdef _WIN32
 #  include <windows.h>
 #else
-#  include <pthread.h>
 #  include <unistd.h>
 #endif
 
@@ -35,7 +34,7 @@ unsigned int System::CPUCores()
 
 void System::SetThreadName( std::thread& thread, const char* name )
 {
-#ifdef _WIN32
+#ifdef _MSC_VER
     const DWORD MS_VC_EXCEPTION=0x406D1388;
 
 #  pragma pack( push, 8 )
@@ -62,7 +61,5 @@ void System::SetThreadName( std::thread& thread, const char* name )
     __except(EXCEPTION_EXECUTE_HANDLER)
     {
     }
-#elif !defined(__APPLE__)
-    pthread_setname_np( thread.native_handle(), name );
 #endif
 }
diff --git a/thirdparty/etcpak/TaskDispatch.cpp b/thirdparty/etcpak/TaskDispatch.cpp
index 7287da4de2..b1ba17953b 100644
--- a/thirdparty/etcpak/TaskDispatch.cpp
+++ b/thirdparty/etcpak/TaskDispatch.cpp
@@ -1,5 +1,8 @@
 #include <assert.h>
 #include <stdio.h>
+#ifndef _MSC_VER
+#include <pthread.h>
+#endif
 
 #include "Debug.hpp"
 #include "System.hpp"
@@ -22,15 +25,19 @@ TaskDispatch::TaskDispatch( size_t workers )
     {
         char tmp[16];
         sprintf( tmp, "Worker %zu", i );
-#ifdef __APPLE__
+#ifdef _MSC_VER
+        auto worker = std::thread( [this]{ Worker(); } );
+        System::SetThreadName( worker, tmp );
+#else // Using pthread.
         auto worker = std::thread( [this, tmp]{
+#ifdef __APPLE__
             pthread_setname_np( tmp );
+#else // Linux or MinGW.
+            pthread_setname_np( pthread_self(), tmp );
+#endif
             Worker();
         } );
-#else
-        auto worker = std::thread( [this]{ Worker(); } );
 #endif
-        System::SetThreadName( worker, tmp );
         m_workers.emplace_back( std::move( worker ) );
     }