summaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
Diffstat (limited to 'src/os')
-rw-r--r--src/os/os2/os2.cpp5
-rw-r--r--src/os/unix/unix.cpp26
-rw-r--r--src/os/windows/win32.cpp7
-rw-r--r--src/os/windows/win32.h6
4 files changed, 32 insertions, 12 deletions
diff --git a/src/os/os2/os2.cpp b/src/os/os2/os2.cpp
index 7b34f528a..9d01a99b8 100644
--- a/src/os/os2/os2.cpp
+++ b/src/os/os2/os2.cpp
@@ -18,6 +18,7 @@
#include "../../core/random_func.hpp"
#include "../../string_func.h"
#include "../../textbuf_gui.h"
+#include "../../thread.h"
#include "table/strings.h"
@@ -226,3 +227,7 @@ void OSOpenBrowser(const char *url)
// stub only
DEBUG(misc, 0, "Failed to open url: %s", url);
}
+
+void SetCurrentThreadName(const char *)
+{
+}
diff --git a/src/os/unix/unix.cpp b/src/os/unix/unix.cpp
index 2f982dea0..024dc8627 100644
--- a/src/os/unix/unix.cpp
+++ b/src/os/unix/unix.cpp
@@ -17,6 +17,7 @@
#include "../../debug.h"
#include "../../string_func.h"
#include "../../fios.h"
+#include "../../thread.h"
#include <dirent.h>
@@ -43,11 +44,17 @@
#include <sys/sysctl.h>
#endif
+#ifndef NO_THREADS
+#include <pthread.h>
+#endif
+
#if defined(__APPLE__)
- #if defined(WITH_SDL)
+# if defined(WITH_SDL)
/* the mac implementation needs this file included in the same file as main() */
- #include <SDL.h>
- #endif
+# include <SDL.h>
+# endif
+
+# include "../macosx/macos.h"
#endif
#include "../../safeguards.h"
@@ -317,4 +324,15 @@ void OSOpenBrowser(const char *url)
DEBUG(misc, 0, "Failed to open url: %s", url);
exit(0);
}
-#endif
+#endif /* __APPLE__ */
+
+void SetCurrentThreadName(const char *threadName) {
+#if !defined(NO_THREADS) && defined(__GLIBC__)
+#if __GLIBC_PREREQ(2, 12)
+ if (threadName) pthread_setname_np(pthread_self(), threadName);
+#endif /* __GLIBC_PREREQ(2, 12) */
+#endif /* !defined(NO_THREADS) && defined(__GLIBC__) */
+#if defined(__APPLE__)
+ MacOSSetThreadName(threadName);
+#endif /* defined(__APPLE__) */
+}
diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp
index 4a4955549..2a72ca1c5 100644
--- a/src/os/windows/win32.cpp
+++ b/src/os/windows/win32.cpp
@@ -30,6 +30,7 @@
#include <errno.h>
#include <sys/stat.h>
#include "../../language.h"
+#include "../../thread.h"
#include "../../safeguards.h"
@@ -816,12 +817,12 @@ PACK_N(struct THREADNAME_INFO {
/**
* Signal thread name to any attached debuggers.
*/
-void SetWin32ThreadName(DWORD dwThreadID, const char* threadName)
+void SetCurrentThreadName(const char *threadName)
{
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = threadName;
- info.dwThreadID = dwThreadID;
+ info.dwThreadID = -1;
info.dwFlags = 0;
#pragma warning(push)
@@ -832,4 +833,6 @@ void SetWin32ThreadName(DWORD dwThreadID, const char* threadName)
}
#pragma warning(pop)
}
+#else
+void SetCurrentThreadName(const char *) {}
#endif
diff --git a/src/os/windows/win32.h b/src/os/windows/win32.h
index 4f813c4a6..23e216762 100644
--- a/src/os/windows/win32.h
+++ b/src/os/windows/win32.h
@@ -39,12 +39,6 @@ HRESULT OTTDSHGetFolderPath(HWND, int, HANDLE, DWORD, LPTSTR);
#define SHGFP_TYPE_CURRENT 0
#endif /* __MINGW32__ */
-#ifdef _MSC_VER
-void SetWin32ThreadName(DWORD dwThreadID, const char* threadName);
-#else
-static inline void SetWin32ThreadName(DWORD dwThreadID, const char* threadName) {}
-#endif
-
void Win32SetCurrentLocaleName(const char *iso_code);
int OTTDStringCompare(const char *s1, const char *s2);