Skip to content

Commit 9dc46af

Browse files
committed
Use gettid() on Linux.
1 parent f583f57 commit 9dc46af

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/include/sampleheap.hpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,19 @@ class SampleHeap : public SuperHeap {
291291
if (_pythonCount == 0) {
292292
_pythonCount = 1; // prevent 0/0
293293
}
294+
// Get the thread ID, which must match the logic used by Python.
294295
uint64_t thread_id;
295-
#if defined(__APPLE__)
296-
// Use OS X / BSD thread identifier function to get "actual" thread ID.
296+
#if defined(__APPLE__) || defined(BSD)
297+
// Use the OS X / BSD thread identifier function to get "actual" thread ID.
297298
pthread_threadid_np(pthread_self(), &thread_id);
299+
#elif defined(__linux__)
300+
// On Linux, use gettid().
301+
thread_id = (uint64_t) gettid();
298302
#else
299-
// On Linux, we cast pthread_self and hope for the best.
303+
// On other systems, cast pthread_self and hope for the best.
300304
thread_id = (uint64_t) pthread_self();
301305
#endif
306+
302307
snprintf_(
303308
buf, sizeof(buf),
304309
#if defined(__APPLE__)

0 commit comments

Comments
 (0)