Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_thread_id implementations for BSDs. #401

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading