summaryrefslogtreecommitdiff
path: root/src/os/unix
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2019-03-17 01:59:46 +0100
committerMichael Lutz <michi@icosahedron.de>2019-04-06 11:27:39 +0200
commit05bc2ed7cbe07cb4cd535932f10778b35f72e944 (patch)
tree0faaf12fd1bafb0786236ffc82052e8b83dfca60 /src/os/unix
parent05f4e7360886e36b221ef5c3af4426625a3de686 (diff)
downloadopenttd-05bc2ed7cbe07cb4cd535932f10778b35f72e944.tar.xz
Codechange: Replace custom thread code with C++11 thread objects.
We assume a conforming C++11 compiler environment that has a valid <thread>-header. Failure to run a real thread is handled gracefully.
Diffstat (limited to 'src/os/unix')
-rw-r--r--src/os/unix/unix.cpp26
1 files changed, 22 insertions, 4 deletions
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__) */
+}