Skip to content

Commit

Permalink
Add get_thread_id implementations for BSDs.
Browse files Browse the repository at this point in the history
  • Loading branch information
KerJoe authored and odygrd committed Mar 14, 2024
1 parent c718304 commit 1e9db34
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions quill/src/detail/misc/Os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,29 @@
#include <sys/stat.h>
#include <syscall.h>
#include <unistd.h>
#elif defined(__NetBSD__)
#include <sched.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <lwp.h>
#elif defined(__FreeBSD__)
#include <sched.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/thr.h>
#elif defined(__DragonFly__)
#include <sched.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/lwp.h>
#else
#include <sched.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#endif

#include "quill/detail/misc/Utilities.h"
Expand Down Expand Up @@ -316,6 +339,16 @@ uint32_t get_thread_id() noexcept
uint64_t tid64;
pthread_threadid_np(nullptr, &tid64);
return static_cast<uint32_t>(tid64);
#elif defined(__NetBSD__)
return static_cast<uint32_t>(_lwp_self());
#elif defined(__FreeBSD__)
long lwpid;
thr_self(&lwpid);
return static_cast<uint32_t>(lwpid);
#elif defined(__DragonFly__)
return static_cast<uint32_t>(lwp_gettid());
#else
return reinterpret_cast<uintptr_t>(pthread_self()); // (Ab)use pthread_self as a last resort option
#endif
}

Expand Down

0 comments on commit 1e9db34

Please sign in to comment.