aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--alc/backends/alsa.cpp2
-rw-r--r--alc/backends/dsound.cpp2
-rw-r--r--alc/backends/jack.cpp1
-rw-r--r--alc/backends/null.cpp4
-rw-r--r--alc/backends/opensl.cpp1
-rw-r--r--alc/backends/oss.cpp2
-rw-r--r--alc/backends/sndio.cpp2
-rw-r--r--alc/backends/solaris.cpp2
-rw-r--r--alc/backends/wasapi.cpp2
-rw-r--r--alc/backends/wave.cpp2
-rw-r--r--alc/backends/winmm.cpp1
-rw-r--r--common/althrd_setname.cpp76
-rw-r--r--common/althrd_setname.h6
-rw-r--r--common/threads.cpp66
-rw-r--r--common/threads.h2
16 files changed, 96 insertions, 77 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e4d3776d..63a213c9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -621,6 +621,8 @@ set(COMMON_OBJS
common/alspan.h
common/alstring.cpp
common/alstring.h
+ common/althrd_setname.cpp
+ common/althrd_setname.h
common/altraits.h
common/atomic.h
common/comptr.h
diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp
index ce368f5e..83eef183 100644
--- a/alc/backends/alsa.cpp
+++ b/alc/backends/alsa.cpp
@@ -41,12 +41,12 @@
#include "alc/alconfig.h"
#include "almalloc.h"
#include "alnumeric.h"
+#include "althrd_setname.h"
#include "core/device.h"
#include "core/helpers.h"
#include "core/logging.h"
#include "dynload.h"
#include "ringbuffer.h"
-#include "threads.h"
#include <alsa/asoundlib.h>
diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp
index 5fc8a1c7..54fac898 100644
--- a/alc/backends/dsound.cpp
+++ b/alc/backends/dsound.cpp
@@ -47,6 +47,7 @@
#include "albit.h"
#include "alnumeric.h"
#include "alspan.h"
+#include "althrd_setname.h"
#include "comptr.h"
#include "core/device.h"
#include "core/helpers.h"
@@ -54,7 +55,6 @@
#include "dynload.h"
#include "ringbuffer.h"
#include "strutils.h"
-#include "threads.h"
/* MinGW-w64 needs this for some unknown reason now. */
using LPCWAVEFORMATEX = const WAVEFORMATEX*;
diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp
index 9e023e21..b8325b05 100644
--- a/alc/backends/jack.cpp
+++ b/alc/backends/jack.cpp
@@ -35,6 +35,7 @@
#include "albit.h"
#include "alc/alconfig.h"
#include "alnumeric.h"
+#include "althrd_setname.h"
#include "core/device.h"
#include "core/helpers.h"
#include "core/logging.h"
diff --git a/alc/backends/null.cpp b/alc/backends/null.cpp
index 5a8fc255..73420ad3 100644
--- a/alc/backends/null.cpp
+++ b/alc/backends/null.cpp
@@ -30,10 +30,10 @@
#include <functional>
#include <thread>
-#include "core/device.h"
+#include "althrd_setname.h"
#include "almalloc.h"
+#include "core/device.h"
#include "core/helpers.h"
-#include "threads.h"
namespace {
diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp
index c9053816..a3b70791 100644
--- a/alc/backends/opensl.cpp
+++ b/alc/backends/opensl.cpp
@@ -35,6 +35,7 @@
#include "albit.h"
#include "alnumeric.h"
+#include "althrd_setname.h"
#include "core/device.h"
#include "core/helpers.h"
#include "core/logging.h"
diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp
index dc18c4c3..554ccc24 100644
--- a/alc/backends/oss.cpp
+++ b/alc/backends/oss.cpp
@@ -43,11 +43,11 @@
#include "alc/alconfig.h"
#include "almalloc.h"
#include "alnumeric.h"
+#include "althrd_setname.h"
#include "core/device.h"
#include "core/helpers.h"
#include "core/logging.h"
#include "ringbuffer.h"
-#include "threads.h"
#include <sys/soundcard.h>
diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp
index 2040dd3a..84c54c62 100644
--- a/alc/backends/sndio.cpp
+++ b/alc/backends/sndio.cpp
@@ -32,11 +32,11 @@
#include <vector>
#include "alnumeric.h"
+#include "althrd_setname.h"
#include "core/device.h"
#include "core/helpers.h"
#include "core/logging.h"
#include "ringbuffer.h"
-#include "threads.h"
#include <sndio.h>
diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp
index ae87e7eb..15dcc98f 100644
--- a/alc/backends/solaris.cpp
+++ b/alc/backends/solaris.cpp
@@ -41,10 +41,10 @@
#include <functional>
#include "alc/alconfig.h"
+#include "althrd_setname.h"
#include "core/device.h"
#include "core/helpers.h"
#include "core/logging.h"
-#include "threads.h"
#include <sys/audioio.h>
diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp
index 32a4334d..2b88aa96 100644
--- a/alc/backends/wasapi.cpp
+++ b/alc/backends/wasapi.cpp
@@ -61,6 +61,7 @@
#include "alc/events.h"
#include "alnumeric.h"
#include "alspan.h"
+#include "althrd_setname.h"
#include "comptr.h"
#include "core/converter.h"
#include "core/device.h"
@@ -68,7 +69,6 @@
#include "core/logging.h"
#include "ringbuffer.h"
#include "strutils.h"
-#include "threads.h"
#if defined(ALSOFT_UWP)
#include <collection.h>
diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp
index 1ee2fe51..40592ee7 100644
--- a/alc/backends/wave.cpp
+++ b/alc/backends/wave.cpp
@@ -38,12 +38,12 @@
#include "alc/alconfig.h"
#include "almalloc.h"
#include "alnumeric.h"
+#include "althrd_setname.h"
#include "core/device.h"
#include "core/helpers.h"
#include "core/logging.h"
#include "opthelpers.h"
#include "strutils.h"
-#include "threads.h"
namespace {
diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp
index 0345fe10..fa5bf22a 100644
--- a/alc/backends/winmm.cpp
+++ b/alc/backends/winmm.cpp
@@ -39,6 +39,7 @@
#include <functional>
#include "alnumeric.h"
+#include "althrd_setname.h"
#include "core/device.h"
#include "core/helpers.h"
#include "core/logging.h"
diff --git a/common/althrd_setname.cpp b/common/althrd_setname.cpp
new file mode 100644
index 00000000..22d33092
--- /dev/null
+++ b/common/althrd_setname.cpp
@@ -0,0 +1,76 @@
+
+#include "config.h"
+
+#include "althrd_setname.h"
+
+
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+void althrd_setname(const char *name [[maybe_unused]])
+{
+#if defined(_MSC_VER) && !defined(_M_ARM)
+
+#define MS_VC_EXCEPTION 0x406D1388
+#pragma pack(push,8)
+ struct {
+ DWORD dwType; // Must be 0x1000.
+ LPCSTR szName; // Pointer to name (in user addr space).
+ DWORD dwThreadID; // Thread ID (-1=caller thread).
+ DWORD dwFlags; // Reserved for future use, must be zero.
+ } info;
+#pragma pack(pop)
+ info.dwType = 0x1000;
+ info.szName = name;
+ info.dwThreadID = ~DWORD{0};
+ info.dwFlags = 0;
+
+ /* FIXME: How to do this on MinGW? */
+ __try {
+ RaiseException(MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info);
+ }
+ __except(EXCEPTION_CONTINUE_EXECUTION) {
+ }
+#undef MS_VC_EXCEPTION
+#endif
+}
+
+#else
+
+#include <pthread.h>
+#ifdef HAVE_PTHREAD_NP_H
+#include <pthread_np.h>
+#endif
+
+namespace {
+
+using setname_t1 = int(*)(const char*);
+using setname_t2 = int(*)(pthread_t, const char*);
+using setname_t3 = void(*)(pthread_t, const char*);
+using setname_t4 = int(*)(pthread_t, const char*, void*);
+
+[[maybe_unused]] void setname_caller(setname_t1 func, const char *name)
+{ func(name); }
+
+[[maybe_unused]] void setname_caller(setname_t2 func, const char *name)
+{ func(pthread_self(), name); }
+
+[[maybe_unused]] void setname_caller(setname_t3 func, const char *name)
+{ func(pthread_self(), name); }
+
+[[maybe_unused]] void setname_caller(setname_t4 func, const char *name)
+{ func(pthread_self(), "%s", static_cast<void*>(const_cast<char*>(name))); }
+
+} // namespace
+
+void althrd_setname(const char *name [[maybe_unused]])
+{
+#if defined(HAVE_PTHREAD_SET_NAME_NP)
+ setname_caller(pthread_set_name_np, name);
+#elif defined(HAVE_PTHREAD_SETNAME_NP)
+ setname_caller(pthread_setname_np, name);
+#endif
+}
+
+#endif
diff --git a/common/althrd_setname.h b/common/althrd_setname.h
new file mode 100644
index 00000000..0e22c0a9
--- /dev/null
+++ b/common/althrd_setname.h
@@ -0,0 +1,6 @@
+#ifndef COMMON_ALTHRD_SETNAME_H
+#define COMMON_ALTHRD_SETNAME_H
+
+void althrd_setname(const char *name);
+
+#endif /* COMMON_ALTHRD_SETNAME_H */
diff --git a/common/threads.cpp b/common/threads.cpp
index c1d9e8b0..c176f5af 100644
--- a/common/threads.cpp
+++ b/common/threads.cpp
@@ -32,37 +32,6 @@
#include <limits>
-void althrd_setname(const char *name)
-{
-#if defined(_MSC_VER) && !defined(_M_ARM)
-
-#define MS_VC_EXCEPTION 0x406D1388
-#pragma pack(push,8)
- struct {
- DWORD dwType; // Must be 0x1000.
- LPCSTR szName; // Pointer to name (in user addr space).
- DWORD dwThreadID; // Thread ID (-1=caller thread).
- DWORD dwFlags; // Reserved for future use, must be zero.
- } info;
-#pragma pack(pop)
- info.dwType = 0x1000;
- info.szName = name;
- info.dwThreadID = ~DWORD{0};
- info.dwFlags = 0;
-
- __try {
- RaiseException(MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info);
- }
- __except(EXCEPTION_CONTINUE_EXECUTION) {
- }
-#undef MS_VC_EXCEPTION
-
-#else
-
- (void)name;
-#endif
-}
-
namespace al {
semaphore::semaphore(unsigned int initial)
@@ -93,41 +62,6 @@ bool semaphore::try_wait() noexcept
#else
-#include <pthread.h>
-#ifdef HAVE_PTHREAD_NP_H
-#include <pthread_np.h>
-#endif
-
-namespace {
-
-using setname_t1 = int(*)(const char*);
-using setname_t2 = int(*)(pthread_t, const char*);
-using setname_t3 = void(*)(pthread_t, const char*);
-using setname_t4 = int(*)(pthread_t, const char*, void*);
-
-[[maybe_unused]] void setname_caller(setname_t1 func, const char *name)
-{ func(name); }
-
-[[maybe_unused]] void setname_caller(setname_t2 func, const char *name)
-{ func(pthread_self(), name); }
-
-[[maybe_unused]] void setname_caller(setname_t3 func, const char *name)
-{ func(pthread_self(), name); }
-
-[[maybe_unused]] void setname_caller(setname_t4 func, const char *name)
-{ func(pthread_self(), "%s", static_cast<void*>(const_cast<char*>(name))); }
-
-} // namespace
-
-void althrd_setname(const char *name [[maybe_unused]])
-{
-#if defined(HAVE_PTHREAD_SET_NAME_NP)
- setname_caller(pthread_set_name_np, name);
-#elif defined(HAVE_PTHREAD_SETNAME_NP)
- setname_caller(pthread_setname_np, name);
-#endif
-}
-
/* Do not try using libdispatch on systems where it is absent. */
#if defined(AL_APPLE_HAVE_DISPATCH)
diff --git a/common/threads.h b/common/threads.h
index 1ef037bb..703d50d4 100644
--- a/common/threads.h
+++ b/common/threads.h
@@ -14,8 +14,6 @@
#include <semaphore.h>
#endif
-void althrd_setname(const char *name);
-
namespace al {
class semaphore {