Skip to content

Commit

Permalink
Add support for FreeBSD
Browse files Browse the repository at this point in the history
In order to get the current thread id on FreeBSD, we can use the
non-portable `pthread_getthreadid_np()` function.
  • Loading branch information
smortex committed May 8, 2024
1 parent 4669dcc commit 0e38da9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ext/vernier/vernier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@

#include <sys/time.h>
#include <signal.h>
#ifdef __APPLE__
#if defined(__APPLE__)
/* macOS */
#include <dispatch/dispatch.h>
#elif defined(__FreeBSD__)
/* FreeBSD */
#include <pthread_np.h>
#include <semaphore.h>
#else
/* Linux */
#include <semaphore.h>
Expand Down Expand Up @@ -786,11 +790,13 @@ class SampleTranslator {

typedef uint64_t native_thread_id_t;
static native_thread_id_t get_native_thread_id() {
#ifdef __APPLE__
#if defined(__APPLE__)
uint64_t thread_id;
int e = pthread_threadid_np(pthread_self(), &thread_id);
if (e != 0) rb_syserr_fail(e, "pthread_threadid_np");
return thread_id;
#elif defined(__FreeBSD__)
return pthread_getthreadid_np();
#else
// gettid() is only available as of glibc 2.30
pid_t tid = syscall(SYS_gettid);
Expand Down

0 comments on commit 0e38da9

Please sign in to comment.