Commit 6d8efa8d authored by gabime's avatar gabime

store thread_id in tls

parent 343904b5
...@@ -294,7 +294,7 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime()) ...@@ -294,7 +294,7 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime())
//Return current thread id as size_t //Return current thread id as size_t
//It exists because the std::this_thread::get_id() is much slower(espcially under VS 2013) //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 #ifdef _WIN32
return static_cast<size_t>(::GetCurrentThreadId()); return static_cast<size_t>(::GetCurrentThreadId());
...@@ -310,11 +310,18 @@ inline size_t thread_id() ...@@ -310,11 +310,18 @@ inline size_t thread_id()
#else //Default to standard C++11 (OSX and other Unix) #else //Default to standard C++11 (OSX and other Unix)
return static_cast<size_t>(std::hash<std::thread::id>()(std::this_thread::get_id())); return static_cast<size_t>(std::hash<std::thread::id>()(std::this_thread::get_id()));
#endif #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) // wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
#define SPDLOG_FILENAME_T(s) L ## s #define SPDLOG_FILENAME_T(s) L ## s
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment