From 0684b4f378eacfd2eccb01e68bed533363b112d9 Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 7 Apr 2015 21:35:41 +0300 Subject: [PATCH] use size_t to better represent thread id across platforms --- include/spdlog/common.h | 1 + include/spdlog/details/async_log_helper.h | 6 +++--- include/spdlog/details/log_msg.h | 2 +- include/spdlog/details/os.h | 8 ++++---- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 8a6bfbf2..630f3fab 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -59,6 +59,7 @@ using log_clock = std::chrono::system_clock; using sink_ptr = std::shared_ptr < sinks::sink > ; using sinks_init_list = std::initializer_list < sink_ptr > ; using formatter_ptr = std::shared_ptr; +using thread_id = std::size_t; //Log level enum namespace level diff --git a/include/spdlog/details/async_log_helper.h b/include/spdlog/details/async_log_helper.h index 9988ff39..e7f6a21f 100644 --- a/include/spdlog/details/async_log_helper.h +++ b/include/spdlog/details/async_log_helper.h @@ -59,7 +59,7 @@ class async_log_helper std::string logger_name; level::level_enum level; log_clock::time_point time; - uint64_t thread_id; + thread_id thread_id; std::string txt; async_msg() = default; @@ -77,7 +77,7 @@ async_msg(async_msg&& other) SPDLOG_NOEXCEPT: logger_name = std::move(other.logger_name); level = other.level; time = std::move(other.time); - thread_id = other.thread_id; + thread_id = other.thread_id; txt = std::move(other.txt); return *this; } @@ -90,7 +90,7 @@ async_msg(async_msg&& other) SPDLOG_NOEXCEPT: logger_name(m.logger_name), level(m.level), time(m.time), - thread_id(m.thread_id), + thread_id(m.thread_id), txt(m.raw.data(), m.raw.size()) {} diff --git a/include/spdlog/details/log_msg.h b/include/spdlog/details/log_msg.h index 34b5ef9a..dc72bcda 100644 --- a/include/spdlog/details/log_msg.h +++ b/include/spdlog/details/log_msg.h @@ -92,7 +92,7 @@ struct log_msg std::string logger_name; level::level_enum level; log_clock::time_point time; - uint64_t thread_id; + thread_id thread_id; fmt::MemoryWriter raw; fmt::MemoryWriter formatted; }; diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 42c62d91..5de99085 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -32,11 +32,11 @@ # define WIN32_LEAN_AND_MEAN # endif # include -#elif __linux__ +#elif __linux__ #include //Use gettid() syscall under linux to get thread id #include #else -#include +#include #endif #include "../common.h" @@ -172,14 +172,14 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime()) } //Return current thread id as 64 bit integer -inline uint64_t thread_id() +inline size_t thread_id() { #ifdef _WIN32 return ::GetCurrentThreadId(); #elif __linux__ return (uint64_t) syscall(SYS_gettid); -#else +#else return (uint64_t) pthread_self(); #endif