0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 08:41:02 +08:00

Get thread id on linux by syscall instead of std::this_thread

This commit is contained in:
Sergey Yagovtsev 2016-09-05 22:02:32 +03:00
parent f5ed51e13a
commit 6d1b9915d2

View File

@ -36,6 +36,9 @@ along with this program.If not, see <http://www.gnu.org/licenses/>.
#include <Windows.h> #include <Windows.h>
#else #else
#include <thread> #include <thread>
#include <sys/types.h>
#include <unistd.h>
#include <sys/syscall.h>
#endif #endif
inline uint32_t getCurrentThreadId() inline uint32_t getCurrentThreadId()
@ -43,8 +46,9 @@ inline uint32_t getCurrentThreadId()
#ifdef _WIN32 #ifdef _WIN32
return (uint32_t)::GetCurrentThreadId(); return (uint32_t)::GetCurrentThreadId();
#else #else
thread_local static uint32_t _id = (uint32_t)std::hash<std::thread::id>()(std::this_thread::get_id()); thread_local static pid_t x = syscall(__NR_gettid);
return _id; thread_local static uint32_t _id = (uint32_t)x;//std::hash<std::thread::id>()(std::this_thread::get_id());
return _id;
#endif #endif
} }
@ -108,8 +112,8 @@ class ThreadStorage final
uint64_t usedMemorySize = 0; uint64_t usedMemorySize = 0;
void clearClosed() { void clearClosed() {
serialized_list_t().swap(closedList); serialized_list_t().swap(closedList);
alloc.clear(); alloc.clear();
usedMemorySize = 0; usedMemorySize = 0;
} }
}; };