Implement thread_ctrl::emergency_exit()
Replace exception throws with this.
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
#include "BEType.h"
|
||||
#include "StrUtil.h"
|
||||
#include "cfmt.h"
|
||||
#include "util/logs.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
#include "Thread.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
@@ -203,7 +205,7 @@ namespace fmt
|
||||
{
|
||||
void raw_error(const char* msg)
|
||||
{
|
||||
throw std::runtime_error{msg};
|
||||
thread_ctrl::emergency_exit(msg);
|
||||
}
|
||||
|
||||
void raw_verify_error(const char* msg, const fmt_type_info* sup, u64 arg)
|
||||
@@ -236,7 +238,7 @@ namespace fmt
|
||||
out += msg;
|
||||
}
|
||||
|
||||
throw std::runtime_error{out};
|
||||
thread_ctrl::emergency_exit(out);
|
||||
}
|
||||
|
||||
void raw_narrow_error(const char* msg, const fmt_type_info* sup, u64 arg)
|
||||
@@ -256,14 +258,14 @@ namespace fmt
|
||||
out += msg;
|
||||
}
|
||||
|
||||
throw std::range_error{out};
|
||||
thread_ctrl::emergency_exit(out);
|
||||
}
|
||||
|
||||
void raw_throw_exception(const char* fmt, const fmt_type_info* sup, const u64* args)
|
||||
{
|
||||
std::string out;
|
||||
raw_append(out, fmt, sup, args);
|
||||
throw std::runtime_error{out};
|
||||
thread_ctrl::emergency_exit(out);
|
||||
}
|
||||
|
||||
struct cfmt_src;
|
||||
|
||||
@@ -2018,6 +2018,31 @@ u64 thread_base::get_cycles()
|
||||
}
|
||||
}
|
||||
|
||||
void thread_ctrl::emergency_exit(std::string_view reason)
|
||||
{
|
||||
sig_log.fatal("Thread terminated due to fatal error: %s", reason);
|
||||
|
||||
if (const auto _this = g_tls_this_thread)
|
||||
{
|
||||
if (_this->finalize(0))
|
||||
{
|
||||
delete _this;
|
||||
}
|
||||
|
||||
// Do some not very useful cleanup
|
||||
thread_base::finalize();
|
||||
|
||||
#ifdef _WIN32
|
||||
_endthreadex(0);
|
||||
#else
|
||||
pthread_exit(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Assume main thread
|
||||
report_fatal_error(std::string(reason));
|
||||
}
|
||||
|
||||
void thread_ctrl::detect_cpu_layout()
|
||||
{
|
||||
if (!g_native_core_layout.compare_and_swap_test(native_core_arrangement::undefined, native_core_arrangement::generic))
|
||||
|
||||
@@ -225,6 +225,9 @@ public:
|
||||
_wait_for(-1, true);
|
||||
}
|
||||
|
||||
// Exit.
|
||||
[[noreturn]] static void emergency_exit(std::string_view reason);
|
||||
|
||||
// Get current thread (may be nullptr)
|
||||
static thread_base* get_current()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user