mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::log: Add assertion for log calls from non-main threads.
This commit is contained in:
parent
1f6d83b5b1
commit
99d75648f0
1 changed files with 16 additions and 1 deletions
|
@ -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<void (std::ostream &)> &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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue