summaryrefslogtreecommitdiff
path: root/src/os/macosx
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2018-01-28 23:45:02 +0100
committerMichael Lutz <michi@icosahedron.de>2018-04-10 23:30:01 +0200
commitf670277ff5ecd9843f379551265ce2ead05134f2 (patch)
treeaf414016a6dd67788f98bb56453886f1de4172d2 /src/os/macosx
parent4971678f521f945b9f6f47042d33d610db43962d (diff)
downloadopenttd-f670277ff5ecd9843f379551265ce2ead05134f2.tar.xz
Codechange: [OSX] Try to set the thread name for debugger display.
Diffstat (limited to 'src/os/macosx')
-rw-r--r--src/os/macosx/macos.h2
-rw-r--r--src/os/macosx/macos.mm19
2 files changed, 21 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 ] ];
+ }
+}