This commit is contained in:
blueloveTH 2022-12-04 02:09:30 +08:00
parent 9b9e1b9fd0
commit e5c96c2732
2 changed files with 11 additions and 7 deletions

View File

@ -840,10 +840,9 @@ extern "C" {
} }
__EXPORT __EXPORT
/// Emit a KeyboardInterrupt signal in order to stop a running threaded virtual machine. /// Emit a KeyboardInterrupt signal to stop a running threaded virtual machine.
void pkpy_tvm_keyboard_interrupt(VM* vm){ void pkpy_tvm_terminate(ThreadedVM* vm){
// although this is a method of VM, it's only used in ThreadedVM vm->terminate();
vm->keyboardInterrupt();
} }
__EXPORT __EXPORT

View File

@ -1088,9 +1088,7 @@ class ThreadedVM : public VM {
void __deleteThread(){ void __deleteThread(){
if(_thread != nullptr){ if(_thread != nullptr){
if(_state == THREAD_RUNNING || _state == THREAD_SUSPENDED){ terminate();
keyboardInterrupt();
}
_thread->join(); _thread->join();
delete _thread; delete _thread;
_thread = nullptr; _thread = nullptr;
@ -1109,6 +1107,13 @@ public:
}); });
} }
void terminate(){
if(_state == THREAD_RUNNING || _state == THREAD_SUSPENDED){
keyboardInterrupt();
while(_state != THREAD_FINISHED);
}
}
void suspend(){ void suspend(){
if(_state != THREAD_RUNNING) UNREACHABLE(); if(_state != THREAD_RUNNING) UNREACHABLE();
_state = THREAD_SUSPENDED; _state = THREAD_SUSPENDED;