LdH::abort
This commit is contained in:
parent
78702435a7
commit
f62215635b
@ -29,6 +29,13 @@ namespace LdH {
|
|||||||
std::cerr << this->formatOutput();
|
std::cerr << this->formatOutput();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export
|
||||||
|
[[noreturn]]
|
||||||
|
void abort(char const *msg) {
|
||||||
|
std::cerr << "Fatal error:\n" << (Exception{msg}).formatOutput() << std::endl;
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module : private;
|
module : private;
|
||||||
@ -48,7 +55,7 @@ std::string LdH::Exception::formatOutput() const {
|
|||||||
std::stringstream builder;
|
std::stringstream builder;
|
||||||
builder << "Exception: " << this->message << '\n';
|
builder << "Exception: " << this->message << '\n';
|
||||||
for (auto const &frame: this->stacktrace) {
|
for (auto const &frame: this->stacktrace) {
|
||||||
builder << "\t" << frame.description();
|
builder << "\t" << frame.description();
|
||||||
if (!frame.source_file().empty()) {
|
if (!frame.source_file().empty()) {
|
||||||
builder << "\t\t" << frame.source_file() << ":" << frame.source_line() << '\n';
|
builder << "\t\t" << frame.source_file() << ":" << frame.source_line() << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -166,7 +166,7 @@ LdH::CommonHighLevelThreadWrapper<native_wrapper_t> &LdH::CommonHighLevelThreadW
|
|||||||
case _thread_state_RUNNING:
|
case _thread_state_RUNNING:
|
||||||
case _thread_state_JOINING:
|
case _thread_state_JOINING:
|
||||||
case _thread_state_JOINED:
|
case _thread_state_JOINED:
|
||||||
throw LdH::Exception{"Variable already initialized"};
|
LdH::abort("Variable already initialized");
|
||||||
}
|
}
|
||||||
new(this)CommonHighLevelThreadWrapper{std::move(other)};
|
new(this)CommonHighLevelThreadWrapper{std::move(other)};
|
||||||
return *this;
|
return *this;
|
||||||
@ -176,16 +176,16 @@ template<class native_wrapper_t> requires LdH::NativeHighLevelThreadWrapper<nati
|
|||||||
void LdH::CommonHighLevelThreadWrapper<native_wrapper_t>::join() {
|
void LdH::CommonHighLevelThreadWrapper<native_wrapper_t>::join() {
|
||||||
switch (this->_cas_state(_thread_state_RUNNING, _thread_state_JOINING)) {
|
switch (this->_cas_state(_thread_state_RUNNING, _thread_state_JOINING)) {
|
||||||
case _thread_state_UNINITIALIZED:
|
case _thread_state_UNINITIALIZED:
|
||||||
throw LdH::Exception{"Variable not initialized"};
|
LdH::abort("Variable not initialized");
|
||||||
case _thread_state_RUNNING:
|
case _thread_state_RUNNING:
|
||||||
break;
|
break;
|
||||||
case _thread_state_JOINING:
|
case _thread_state_JOINING:
|
||||||
case _thread_state_JOINED:
|
case _thread_state_JOINED:
|
||||||
throw LdH::Exception{"Thread already joined"};
|
LdH::abort("Thread already joined");
|
||||||
case _thread_state_DESTROYED:
|
case _thread_state_DESTROYED:
|
||||||
throw LdH::Exception{"Thread already destroyed"};
|
LdH::abort("Thread already destroyed");
|
||||||
case _thread_state_MOVED:
|
case _thread_state_MOVED:
|
||||||
throw LdH::Exception{"Content of this variable was moved to another variable"};
|
LdH::abort("Content of this variable was moved to another variable");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,16 +197,16 @@ template<class native_wrapper_t> requires LdH::NativeHighLevelThreadWrapper<nati
|
|||||||
void LdH::CommonHighLevelThreadWrapper<native_wrapper_t>::destroy() {
|
void LdH::CommonHighLevelThreadWrapper<native_wrapper_t>::destroy() {
|
||||||
switch (this->_cas_state(_thread_state_JOINED, _thread_state_DESTROYED)) {
|
switch (this->_cas_state(_thread_state_JOINED, _thread_state_DESTROYED)) {
|
||||||
case _thread_state_UNINITIALIZED:
|
case _thread_state_UNINITIALIZED:
|
||||||
throw LdH::Exception{"Variable not initialized"};
|
LdH::abort("Variable not initialized");
|
||||||
case _thread_state_RUNNING:
|
case _thread_state_RUNNING:
|
||||||
case _thread_state_JOINING:
|
case _thread_state_JOINING:
|
||||||
throw LdH::Exception{"Thread not finished yet"};
|
LdH::abort("Thread not finished yet");
|
||||||
case _thread_state_JOINED:
|
case _thread_state_JOINED:
|
||||||
break;
|
break;
|
||||||
case _thread_state_DESTROYED:
|
case _thread_state_DESTROYED:
|
||||||
throw LdH::Exception{"Thread already destroyed"};
|
LdH::abort("Thread already destroyed");
|
||||||
case _thread_state_MOVED:
|
case _thread_state_MOVED:
|
||||||
throw LdH::Exception{"Content of this variable was moved to another variable"};
|
LdH::abort("Content of this variable was moved to another variable");
|
||||||
}
|
}
|
||||||
this->_native.destroy();
|
this->_native.destroy();
|
||||||
}
|
}
|
||||||
@ -219,9 +219,9 @@ LdH::CommonHighLevelThreadWrapper<native_wrapper_t>::~CommonHighLevelThreadWrapp
|
|||||||
break;
|
break;
|
||||||
case _thread_state_RUNNING:
|
case _thread_state_RUNNING:
|
||||||
case _thread_state_JOINING:
|
case _thread_state_JOINING:
|
||||||
throw LdH::Exception{"Thread not finished yet"};
|
LdH::abort("Thread not finished yet");
|
||||||
case _thread_state_JOINED:
|
case _thread_state_JOINED:
|
||||||
throw LdH::Exception{"Thread not destroyed yet"};
|
LdH::abort("Thread not destroyed yet");
|
||||||
case _thread_state_DESTROYED:
|
case _thread_state_DESTROYED:
|
||||||
break;
|
break;
|
||||||
case _thread_state_MOVED:
|
case _thread_state_MOVED:
|
||||||
|
|||||||
@ -32,11 +32,11 @@ namespace LdH {
|
|||||||
case WAIT_TIMEOUT:
|
case WAIT_TIMEOUT:
|
||||||
continue;
|
continue;
|
||||||
case WAIT_ABANDONED:
|
case WAIT_ABANDONED:
|
||||||
throw LdH::Exception{"Unexpected return WAIT_ABANDONED of WaitForSingleObject"};
|
LdH::abort("Unexpected return WAIT_ABANDONED of WaitForSingleObject");
|
||||||
case WAIT_OBJECT_0:
|
case WAIT_OBJECT_0:
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
throw LdH::Exception{"Unexpected return of WaitForSingleObject"};
|
LdH::abort("Unexpected return of WaitForSingleObject");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,9 +79,11 @@ namespace LdH {
|
|||||||
static DWORD kernel_ret() {
|
static DWORD kernel_ret() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit NativeThreadWrapperForWindows(HANDLE hThread) : _hThread{hThread} {
|
explicit NativeThreadWrapperForWindows(HANDLE hThread) : _hThread{hThread} {
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static NativeThreadWrapperForWindows start(std::string &, DWORD (*kernel)(void *), void *kernel_arg) {
|
static NativeThreadWrapperForWindows start(std::string &, DWORD (*kernel)(void *), void *kernel_arg) {
|
||||||
HANDLE hThread = CreateThread(
|
HANDLE hThread = CreateThread(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user