diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 9233ed57..a5ca8b2f 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -294,7 +294,7 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime()) //Return current thread id as size_t //It exists because the std::this_thread::get_id() is much slower(espcially under VS 2013) -inline size_t thread_id() +inline size_t _thread_id() { #ifdef _WIN32 return static_cast(::GetCurrentThreadId()); @@ -310,10 +310,17 @@ inline size_t thread_id() #else //Default to standard C++11 (OSX and other Unix) return static_cast(std::hash()(std::this_thread::get_id())); #endif - - } +//Return current thread id as size_t (from thread local storage) +inline size_t thread_id() +{ + static thread_local const size_t tid = _thread_id(); + return tid; +} + + + // wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined) #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)