Skip to content

Commit 414acbd

Browse files
authored
Unbreak FreeBSD cross-build on MacOS broken in 051460b
MacOS used FreeBSD-compatible getprogname() and pthread_getname_np(). But pthread_getthreadid_np() does not exist on MacOS. This implements libspl_gettid() using pthread_threadid_np() to get the thread id of the current thread. Tested with FreeBSD GitHub actions freebsd-src/.github/workflows/cross-bootstrap-tools.yml Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Rob Norris <[email protected]> Signed-off-by: Martin Matuska <[email protected]> Closes #16167
1 parent 3400127 commit 414acbd

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/libspl/assert.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@
4141
#define libspl_getprogname() (program_invocation_short_name)
4242
#define libspl_getthreadname(buf, len) \
4343
prctl(PR_GET_NAME, (unsigned long)(buf), 0, 0, 0)
44-
#elif defined(__FreeBSD__)
44+
#elif defined(__FreeBSD__) || defined(__APPLE__)
45+
#if !defined(__APPLE__)
4546
#include <pthread_np.h>
4647
#define libspl_gettid() pthread_getthreadid_np()
48+
#endif
4749
#define libspl_getprogname() getprogname()
4850
#define libspl_getthreadname(buf, len) \
4951
pthread_getname_np(pthread_self(), buf, len);
@@ -98,6 +100,19 @@ libspl_dump_backtrace(void)
98100
#define libspl_dump_backtrace()
99101
#endif
100102

103+
#if defined(__APPLE__)
104+
static inline uint64_t
105+
libspl_gettid(void)
106+
{
107+
uint64_t tid;
108+
109+
if (pthread_threadid_np(NULL, &tid) != 0)
110+
tid = 0;
111+
112+
return (tid);
113+
}
114+
#endif
115+
101116
static boolean_t libspl_assert_ok = B_FALSE;
102117

103118
void
@@ -128,7 +143,11 @@ libspl_assertf(const char *file, const char *func, int line,
128143

129144
fprintf(stderr, "\n"
130145
" PID: %-8u COMM: %s\n"
146+
#if defined(__APPLE__)
147+
" TID: %-8" PRIu64 " NAME: %s\n",
148+
#else
131149
" TID: %-8u NAME: %s\n",
150+
#endif
132151
getpid(), libspl_getprogname(),
133152
libspl_gettid(), tname);
134153

0 commit comments

Comments
 (0)