Skip to content

Commit 8b93b98

Browse files
committed
fix: correctly implement set_thread_name on macos
1 parent a823461 commit 8b93b98

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/helper/graphic_utils.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,14 @@ void utils::exit(int status_code) {
196196
// inspired by SDL_SYS_SetupThread also uses that code for most platforms
197197
OOPETRIS_GRAPHICS_EXPORTED void utils::set_thread_name(const char* name) {
198198

199-
#if defined(__APPLE__) || defined(__linux__) || defined(__ANDROID__) || defined(FLATPAK_BUILD)
199+
#if defined(__APPLE__) || defined(__MACOSX__)
200+
if (pthread_setname_np(name) == ERANGE) {
201+
char namebuf[16] = {}; /* Limited to 16 chars (with 0 byte) */
202+
memcpy(namebuf, name, 15);
203+
namebuf[15] = '\0';
204+
pthread_setname_np(namebuf);
205+
}
206+
#elif defined(__linux__) || defined(__ANDROID__) || defined(FLATPAK_BUILD)
200207
if (pthread_setname_np(pthread_self(), name) == ERANGE) {
201208
char namebuf[16] = {}; /* Limited to 16 chars (with 0 byte) */
202209
memcpy(namebuf, name, 15);

0 commit comments

Comments
 (0)