From 99d75648f033b16f8739dcf2cc9f8e80c38fb612 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 23 Mar 2017 14:59:38 -0700 Subject: [PATCH] ircd::log: Add assertion for log calls from non-main threads. --- ircd/logger.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ircd/logger.cc b/ircd/logger.cc index dc84aafc9..859c288eb 100644 --- a/ircd/logger.cc +++ b/ircd/logger.cc @@ -73,6 +73,13 @@ static void open(const facility &fac); static void prefix(const facility &fac, const char *const &date); static void suffix(const facility &fac); +const auto main_thread_id +{ + std::this_thread::get_id() +}; + +void thread_assertion(); + } // namespace log } // namespace ircd @@ -265,6 +272,8 @@ void log::slog(const facility &fac, const std::function &closure) { + void thread_assertion(); + if(!file[fac].is_open() && !console_out[fac] && !console_err[fac]) return; @@ -367,7 +376,6 @@ log::reflect(const facility &f) return "??????"; } - const char * ircd::smalldate(const time_t <ime) { @@ -387,3 +395,10 @@ ircd::smalldate(const time_t <ime) return buf; } + +void +ircd::log::thread_assertion() +{ + // Trying to log from another thread is not yet allowed + assert(std::this_thread::get_id() == main_thread_id); +}