Skip to content

Commit 955faef

Browse files
deem0nJohnSully
authored andcommitted
Fix to support FreeBSD pthread_getthreadid_np call
1 parent 02b533f commit 955faef

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/fastlock.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
#include <sched.h>
3636
#include <atomic>
3737
#include <assert.h>
38+
#ifdef __FreeBSD__
39+
#include <pthread_np.h>
40+
#else
3841
#include <pthread.h>
42+
#endif
3943
#include <limits.h>
4044
#include <map>
4145
#ifdef __linux__
@@ -167,7 +171,12 @@ extern "C" pid_t gettid()
167171
#else
168172
if (pidCache == -1) {
169173
uint64_t tidT;
174+
#ifdef __FreeBSD__
175+
// Check https://github.com/ClickHouse/ClickHouse/commit/8d51824ddcb604b6f179a0216f0d32ba5612bd2e
176+
tidT = pthread_getthreadid_np();
177+
#else
170178
pthread_threadid_np(nullptr, &tidT);
179+
#endif
171180
serverAssert(tidT < UINT_MAX);
172181
pidCache = (int)tidT;
173182
}
@@ -493,4 +502,4 @@ void fastlock_auto_adjust_waits()
493502
#else
494503
g_fHighCpuPressure = g_fTestMode;
495504
#endif
496-
}
505+
}

0 commit comments

Comments
 (0)