--*/
#if defined(__linux__)
-#define THREADSilentGetCurrentThreadId() (SIZE_T)syscall(SYS_gettid)
+#define PlatformGetCurrentThreadId() (SIZE_T)syscall(SYS_gettid)
#elif defined(__APPLE__)
-inline SIZE_T THREADSilentGetCurrentThreadId() {
+inline SIZE_T PlatformGetCurrentThreadId() {
uint64_t tid;
pthread_threadid_np(pthread_self(), &tid);
return (SIZE_T)tid;
}
#elif defined(__FreeBSD__)
#include <sys/thr.h>
-inline SIZE_T THREADSilentGetCurrentThreadId() {
+inline SIZE_T PlatformGetCurrentThreadId() {
long tid;
thr_self(&tid);
return (SIZE_T)tid;
}
#elif defined(__NetBSD__)
#include <lwp.h>
-#define THREADSilentGetCurrentThreadId() (SIZE_T)_lwp_self()
+#define PlatformGetCurrentThreadId() (SIZE_T)_lwp_self()
#else
-#define THREADSilentGetCurrentThreadId() (SIZE_T)pthread_self()
+#define PlatformGetCurrentThreadId() (SIZE_T)pthread_self()
#endif
+inline SIZE_T THREADSilentGetCurrentThreadId() {
+ static __thread SIZE_T tid;
+ if (!tid)
+ tid = PlatformGetCurrentThreadId();
+ return tid;
+}
+
#endif // _PAL_THREAD_HPP_