| 16 | |
| 17 | static thread_local uint64_t current_tid = 0; |
| 18 | uint64_t getThreadId() |
| 19 | { |
| 20 | if (!current_tid) |
| 21 | { |
| 22 | #if defined(OS_ANDROID) |
| 23 | current_tid = gettid(); |
| 24 | #elif defined(OS_LINUX) |
| 25 | current_tid = syscall(SYS_gettid); /// This call is always successful. - man gettid |
| 26 | #elif defined(OS_FREEBSD) |
| 27 | current_tid = pthread_getthreadid_np(); |
| 28 | #elif defined(OS_SUNOS) |
| 29 | // On Solaris-derived systems, this returns the ID of the LWP, analogous |
| 30 | // to a thread. |
| 31 | current_tid = static_cast<uint64_t>(pthread_self()); |
| 32 | #else |
| 33 | if (0 != pthread_threadid_np(nullptr, ¤t_tid)) |
| 34 | throw std::logic_error("pthread_threadid_np returned error"); |
| 35 | #endif |
| 36 | } |
| 37 | |
| 38 | return current_tid; |
| 39 | } |
no outgoing calls
no test coverage detected