Skip to content

Commit a03b16c

Browse files
committed
feat(port): implement current thread ID on FreeBSD
Make all tests pass on FreeBSD by implementing a missing portability function.
1 parent 1dd9528 commit a03b16c

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Semantic Versioning.
3333
the language standard.
3434
* `((x)) => {}` no longer crashes the parser with an assertion failure.
3535
* Tests now pass if the user's locale is Italian (`it_IT.utf8` on Linux).
36-
* The FreeBSD build now succeeds.
36+
* The FreeBSD build now succeeds and tests pass.
3737

3838
## 2.5.0 (2022-05-23)
3939

src/quick-lint-js/have.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,19 @@
403403
#define QLJS_HAVE_SETJMP 0
404404
#endif
405405

406+
#if !defined(QLJS_HAVE_SYS_THR_H) && defined(__has_include)
407+
#if __has_include(<sys/thr.h>)
408+
#define QLJS_HAVE_SYS_THR_H 1
409+
#endif
410+
#endif
411+
#if !defined(QLJS_HAVE_SYS_THR_H)
412+
#if defined(__FreeBSD__)
413+
#define QLJS_HAVE_SYS_THR_H 1
414+
#else
415+
#define QLJS_HAVE_SYS_THR_H 0
416+
#endif
417+
#endif
418+
406419
#if !defined(QLJS_HAVE_INOTIFY)
407420
#if defined(__linux__)
408421
#define QLJS_HAVE_INOTIFY 1

src/thread.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include <mach/thread_act.h>
2828
#endif
2929

30+
#if QLJS_HAVE_SYS_THR_H
31+
#include <sys/thr.h>
32+
#endif
33+
3034
#if QLJS_HAVE_GETTID
3135
#include <sys/types.h>
3236
#endif
@@ -204,6 +208,11 @@ std::uint64_t get_current_thread_id() noexcept {
204208
QLJS_ALWAYS_ASSERT(rc == KERN_SUCCESS);
205209
QLJS_ALWAYS_ASSERT(info_count == THREAD_IDENTIFIER_INFO_COUNT);
206210
return info.thread_id;
211+
#elif QLJS_HAVE_SYS_THR_H
212+
long thread_id;
213+
int rc = ::thr_self(&thread_id);
214+
QLJS_ALWAYS_ASSERT(rc == 0);
215+
return narrow_cast<std::uint64_t>(thread_id);
207216
#else
208217
#warning "Unsupported platform"
209218
return 0;

0 commit comments

Comments
 (0)