mirror of https://github.com/OpenTTD/OpenTTD
Codechange: [OSX] Try to set the thread name for debugger display.
parent
4971678f52
commit
f670277ff5
|
@ -38,4 +38,6 @@ static inline bool MacOSVersionIsAtLeast(long major, long minor, long bugfix)
|
||||||
|
|
||||||
bool IsMonospaceFont(CFStringRef name);
|
bool IsMonospaceFont(CFStringRef name);
|
||||||
|
|
||||||
|
void MacOSSetThreadName(const char *name);
|
||||||
|
|
||||||
#endif /* MACOS_H */
|
#endif /* MACOS_H */
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "../../rev.h"
|
#include "../../rev.h"
|
||||||
#include "macos.h"
|
#include "macos.h"
|
||||||
#include "../../string_func.h"
|
#include "../../string_func.h"
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#define Rect OTTDRect
|
#define Rect OTTDRect
|
||||||
#define Point OTTDPoint
|
#define Point OTTDPoint
|
||||||
|
@ -233,3 +234,21 @@ bool IsMonospaceFont(CFStringRef name)
|
||||||
|
|
||||||
return font != NULL ? [ font isFixedPitch ] : false;
|
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 ] ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include "../os/macosx/macos.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "../safeguards.h"
|
#include "../safeguards.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,6 +73,9 @@ private:
|
||||||
pthread_setname_np(pthread_self(), self->name);
|
pthread_setname_np(pthread_self(), self->name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
MacOSSetThreadName(self->name);
|
||||||
#endif
|
#endif
|
||||||
self->ThreadProc();
|
self->ThreadProc();
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
|
|
Loading…
Reference in New Issue