Allow threads to be terminated

This commit is contained in:
Anaïs Betts 2022-01-09 18:04:57 +01:00
parent cee9704330
commit a9a9d8927f
2 changed files with 14 additions and 0 deletions

View File

@ -20,6 +20,7 @@ extern unique_pointer<Emulator::Interface> emulator;
#include <nall/encode/zip.hpp>
#include <nall/hash/crc16.hpp>
#include <nall/atomic-queue.hpp>
#include <nall/thread.hpp>
#include "program/program.hpp"
#include "input/input.hpp"

View File

@ -18,6 +18,7 @@ namespace nall {
struct thread {
inline auto join() -> void;
inline auto cancel() -> void;
static inline auto create(const function<void (uintptr)>& callback, uintptr parameter = 0, uint stacksize = 0) -> thread;
static inline auto detach() -> void;
@ -66,6 +67,11 @@ auto thread::exit() -> void {
pthread_exit(nullptr);
}
auto thread::cancel() -> void {
pthread_cancel(handle);
pthread_join(handle, nullptr);
}
}
#elif defined(API_WINDOWS)
@ -75,6 +81,7 @@ namespace nall {
struct thread {
inline ~thread();
inline auto join() -> void;
inline auto cancel() -> void;
static inline auto create(const function<void (uintptr)>& callback, uintptr parameter = 0, uint stacksize = 0) -> thread;
static inline auto detach() -> void;
@ -132,6 +139,12 @@ auto thread::exit() -> void {
ExitThread(0);
}
auto thread::cancel() -> void {
TerminateThread(handle, 0);
WaitForSingleObject(handle, INFINITE);
CloseHandle(handle);
handle = 0;
}
}
#endif