From 5b7557acd49c434f278fcc64ac884fb097f61a4f Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Tue, 10 Aug 2021 16:29:52 +0000 Subject: [PATCH 1/2] Thread: unbreak on BSDs after 50d9d7ea6f2a Common/Thread/ThreadUtil.cpp:149:2: error: use of undeclared identifier 'pthread_threadid_np' pthread_threadid_np(NULL, &tid); ^ --- Common/Thread/ThreadUtil.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Common/Thread/ThreadUtil.cpp b/Common/Thread/ThreadUtil.cpp index 950ef3042a..dd8ea51ed7 100644 --- a/Common/Thread/ThreadUtil.cpp +++ b/Common/Thread/ThreadUtil.cpp @@ -33,6 +33,12 @@ #include #endif +#if defined(__DragonFly__) || defined(__FreeBSD__) +#include +#elif defined(__NetBSD__) +#include +#endif + #ifdef TLS_SUPPORTED static thread_local const char *curThreadName; #endif @@ -144,7 +150,7 @@ int GetCurrentThreadIdForDebug() { return 1; #elif PPSSPP_PLATFORM(WINDOWS) return (int)GetCurrentThreadId(); -#elif PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) || defined(__OpenBSD__) || defined(__FreeBSD__) +#elif PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) uint64_t tid = 0; pthread_threadid_np(NULL, &tid); return (int)tid; @@ -152,6 +158,12 @@ int GetCurrentThreadIdForDebug() { // See issue 14545 return (int)syscall(__NR_gettid); // return (int)gettid(); +#elif defined(__DragonFly__) || defined(__FreeBSD__) + return pthread_getthreadid_np(); +#elif defined(__NetBSD__) + return _lwp_self(); +#elif defined(__OpenBSD__) + return getthrid(); #else return 1; #endif From ae399232239db877ff1a67244e602013cce183c0 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Tue, 10 Aug 2021 16:37:14 +0000 Subject: [PATCH 2/2] Thread: set names on BSDs after 062566b67cb0 --- Common/Thread/ThreadUtil.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Common/Thread/ThreadUtil.cpp b/Common/Thread/ThreadUtil.cpp index dd8ea51ed7..7381279295 100644 --- a/Common/Thread/ThreadUtil.cpp +++ b/Common/Thread/ThreadUtil.cpp @@ -33,7 +33,7 @@ #include #endif -#if defined(__DragonFly__) || defined(__FreeBSD__) +#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) #include #elif defined(__NetBSD__) #include @@ -125,6 +125,10 @@ void SetCurrentThreadName(const char* threadName) { pthread_setname_np(pthread_self(), threadName); #elif defined(__APPLE__) pthread_setname_np(threadName); +#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) + pthread_set_name_np(pthread_self(), threadName); +#elif defined(__NetBSD__) + pthread_setname_np(pthread_self(), "%s", (void*)threadName); #endif // Do nothing