mirror of
https://github.com/KjellKod/g3log.git
synced 2025-03-01 10:57:57 +01:00
Merge pull request #94 from KjellKod/Fatal_exit_For_Erronous_Initialization
Avoid initialization/shutdown deadlock
This commit is contained in:
commit
e58cc942dd
@ -31,7 +31,8 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
std::once_flag g_initialize_flag;
|
||||
@ -63,8 +64,15 @@ namespace g3 {
|
||||
installCrashHandler();
|
||||
});
|
||||
std::lock_guard<std::mutex> lock(g_logging_init_mutex);
|
||||
CHECK(!internal::isLoggingInitialized());
|
||||
CHECK(bgworker != nullptr);
|
||||
if (internal::isLoggingInitialized() || nullptr == bgworker) {
|
||||
std::ostringstream exitMsg;
|
||||
exitMsg << __FILE__ "->" << __FUNCTION__ << ":" << __LINE__ << std::endl;
|
||||
exitMsg << "\tFatal exit due to illegal initialization of g3::LogWorker\n";
|
||||
exitMsg << "\t(due to multiple initializations? : " << std::boolalpha << internal::isLoggingInitialized();
|
||||
exitMsg << ", due to nullptr == bgworker? : " << std::boolalpha << (nullptr == bgworker) << ")";
|
||||
std::cerr << exitMsg.str() << std::endl;
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Save the first uninitialized message, if any
|
||||
std::call_once(g_save_first_unintialized_flag, [&bgworker] {
|
||||
|
Loading…
x
Reference in New Issue
Block a user