added SPDLOG_DISABLE_TID_CACHING macro to prevent invalid thread ids after fork
This commit is contained in:
		
							parent
							
								
									adbc22096a
								
							
						
					
					
						commit
						799ba2a57b
					
				@ -316,7 +316,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)
 | 
			
		||||
//It exists because the std::this_thread::get_id() is much slower(especially under VS 2013)
 | 
			
		||||
inline size_t _thread_id()
 | 
			
		||||
{
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
@ -342,17 +342,17 @@ inline size_t _thread_id()
 | 
			
		||||
//Return current thread id as size_t (from thread local storage)
 | 
			
		||||
inline size_t thread_id()
 | 
			
		||||
{
 | 
			
		||||
#if defined(_MSC_VER) && (_MSC_VER < 1900) || defined(__clang__) && !__has_feature(cxx_thread_local)
 | 
			
		||||
#if defined(SPDLOG_DISABLE_TID_CACHING) || (defined(_MSC_VER) && (_MSC_VER < 1900)) || (defined(__clang__) && !__has_feature(cxx_thread_local))
 | 
			
		||||
    return _thread_id();
 | 
			
		||||
#else
 | 
			
		||||
#else // cache thread id in tls
 | 
			
		||||
    static thread_local const size_t tid = _thread_id();
 | 
			
		||||
    return tid;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
 | 
			
		||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
 | 
			
		||||
#define SPDLOG_FILENAME_T(s) L ## s
 | 
			
		||||
@ -424,7 +424,7 @@ inline int pid()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Detrmine if the terminal supports colors
 | 
			
		||||
// Determine if the terminal supports colors
 | 
			
		||||
// Source: https://github.com/agauniyal/rang/
 | 
			
		||||
inline bool is_color_terminal()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
@ -23,7 +23,7 @@
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Uncomment if date/time logging is not needed and never appear in the log pattern.
 | 
			
		||||
// This will prevent spdlog from quering the clock on each log call.
 | 
			
		||||
// This will prevent spdlog from querying the clock on each log call.
 | 
			
		||||
//
 | 
			
		||||
// WARNING: If the log pattern contains any date/time while this flag is on, the result is undefined.
 | 
			
		||||
//          You must set new pattern(spdlog::set_pattern(..") without any date/time in it
 | 
			
		||||
@ -34,7 +34,7 @@
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Uncomment if thread id logging is not needed (i.e. no %t in the log pattern).
 | 
			
		||||
// This will prevent spdlog from quering the thread id on each log call.
 | 
			
		||||
// This will prevent spdlog from querying the thread id on each log call.
 | 
			
		||||
//
 | 
			
		||||
// WARNING: If the log pattern contains thread id (i.e, %t) while this flag is on, the result is undefined.
 | 
			
		||||
//
 | 
			
		||||
@ -42,6 +42,16 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Uncomment to prevent spdlog from caching thread ids in thread local storage.
 | 
			
		||||
// By default spdlog saves thread ids in tls to gain a few micros for each call.
 | 
			
		||||
//
 | 
			
		||||
// WARNING: if your program forks, UNCOMMENT this flag to prevent undefined thread ids in the children logs.
 | 
			
		||||
//
 | 
			
		||||
// #define SPDLOG_DISABLE_TID_CACHING
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Uncomment if logger name logging is not needed.
 | 
			
		||||
// This will prevent spdlog from copying the logger name  on each log call.
 | 
			
		||||
@ -59,7 +69,7 @@
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Uncomment to avoid locking in the registry operations (spdlog::get(), spdlog::drop() spdlog::register()).
 | 
			
		||||
// Use only if your code never modifes concurrently the registry.
 | 
			
		||||
// Use only if your code never modifies concurrently the registry.
 | 
			
		||||
// Note that upon creating a logger the registry is modified by spdlog..
 | 
			
		||||
//
 | 
			
		||||
// #define SPDLOG_NO_REGISTRY_MUTEX
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user