diff --git a/src/profile_manager.cpp b/src/profile_manager.cpp index 4dff626..769ce67 100644 --- a/src/profile_manager.cpp +++ b/src/profile_manager.cpp @@ -116,15 +116,14 @@ void ProfileManager::beginBlock(Block* _block) } } - void ProfileManager::endBlock() { if (!m_isEnabled) return; - uint32_t threadId = std::hash()(std::this_thread::get_id()); - + uint32_t threadId = getThreadId(); + guard_lock_t lock(m_spin); auto& stackOfOpenedBlocks = m_openedBracketsMap[threadId]; @@ -151,3 +150,17 @@ void ProfileManager::_internalInsertBlock(profiler::Block* _block) m_blocks.emplace_back(new SerilizedBlock(_block)); } +#ifdef WIN32 +#include +#else +#include +#endif + +uint32_t ProfileManager::getThreadId() +{ +#ifdef WIN32 + return (uint32_t)::GetCurrentThreadId(); +#else + return (uint32_t)pthread_self(); +#endif +} diff --git a/src/profile_manager.h b/src/profile_manager.h index 4b726d2..eb33bfa 100644 --- a/src/profile_manager.h +++ b/src/profile_manager.h @@ -49,6 +49,8 @@ class ProfileManager typedef std::list serialized_list_t; serialized_list_t m_blocks; + + uint32_t getThreadId(); public: static ProfileManager& instance(); ~ProfileManager();