diff options
-rw-r--r-- | src/os/macosx/macos.h | 2 | ||||
-rw-r--r-- | src/os/macosx/macos.mm | 19 | ||||
-rw-r--r-- | src/thread/thread_pthread.cpp | 7 |
3 files changed, 28 insertions, 0 deletions
diff --git a/src/os/macosx/macos.h b/src/os/macosx/macos.h index 1e6729f12..4204d93bb 100644 --- a/src/os/macosx/macos.h +++ b/src/os/macosx/macos.h @@ -38,4 +38,6 @@ static inline bool MacOSVersionIsAtLeast(long major, long minor, long bugfix) bool IsMonospaceFont(CFStringRef name); +void MacOSSetThreadName(const char *name); + #endif /* MACOS_H */ diff --git a/src/os/macosx/macos.mm b/src/os/macosx/macos.mm index 1d388d393..7fb71fe9e 100644 --- a/src/os/macosx/macos.mm +++ b/src/os/macosx/macos.mm @@ -14,6 +14,7 @@ #include "../../rev.h" #include "macos.h" #include "../../string_func.h" +#include <pthread.h> #define Rect OTTDRect #define Point OTTDPoint @@ -233,3 +234,21 @@ bool IsMonospaceFont(CFStringRef name) return font != NULL ? [ font isFixedPitch ] : false; } + +/** + * Set the name of the current thread for the debugger. + * @param name The new name of the current thread. + */ +void MacOSSetThreadName(const char *name) +{ +#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) + if (MacOSVersionIsAtLeast(10, 6, 0)) { + pthread_setname_np(name); + } +#endif + + NSThread *cur = [ NSThread currentThread ]; + if (cur != NULL && [ cur respondsToSelector:@selector(setName:) ]) { + [ cur performSelector:@selector(setName:) withObject:[ NSString stringWithUTF8String:name ] ]; + } +} diff --git a/src/thread/thread_pthread.cpp b/src/thread/thread_pthread.cpp index 747b8943d..8aed5ee13 100644 --- a/src/thread/thread_pthread.cpp +++ b/src/thread/thread_pthread.cpp @@ -14,6 +14,10 @@ #include <pthread.h> #include <errno.h> +#if defined(__APPLE__) +#include "../os/macosx/macos.h" +#endif + #include "../safeguards.h" /** @@ -70,6 +74,9 @@ private: } #endif #endif +#if defined(__APPLE__) + MacOSSetThreadName(self->name); +#endif self->ThreadProc(); pthread_exit(NULL); } |