XThread Terminate

This commit is contained in:
Dr. Chat 2015-07-05 14:44:43 -05:00
parent 7f53b1d630
commit 778acac929
2 changed files with 32 additions and 0 deletions

View File

@ -337,6 +337,8 @@ X_STATUS XThread::Create() {
} }
X_STATUS XThread::Exit(int exit_code) { X_STATUS XThread::Exit(int exit_code) {
assert_true(XThread::GetCurrentThread() == this);
// TODO(benvanik): set exit code in thread state block // TODO(benvanik): set exit code in thread state block
// TODO(benvanik); dispatch events? waiters? etc? // TODO(benvanik); dispatch events? waiters? etc?
@ -359,6 +361,21 @@ X_STATUS XThread::Exit(int exit_code) {
return X_STATUS_SUCCESS; return X_STATUS_SUCCESS;
} }
X_STATUS XThread::Terminate(int exit_code) {
if (event_) {
event_->Set(0, false);
}
// TODO: Inform the profiler that this thread is exiting.
Release();
X_STATUS status = PlatformTerminate(exit_code);
if (XFAILED(status)) {
return status;
}
return X_STATUS_SUCCESS;
}
#if XE_PLATFORM_WIN32 #if XE_PLATFORM_WIN32
static uint32_t __stdcall XThreadStartCallbackWin32(void* param) { static uint32_t __stdcall XThreadStartCallbackWin32(void* param) {
@ -406,6 +423,14 @@ X_STATUS XThread::PlatformExit(int exit_code) {
return X_STATUS_SUCCESS; return X_STATUS_SUCCESS;
} }
X_STATUS XThread::PlatformTerminate(int exit_code) {
if (!TerminateThread(thread_handle_, exit_code)) {
return X_STATUS_UNSUCCESSFUL;
}
return X_STATUS_SUCCESS;
}
#else #else
static void* XThreadStartCallbackPthreads(void* param) { static void* XThreadStartCallbackPthreads(void* param) {
@ -465,6 +490,11 @@ X_STATUS XThread::PlatformExit(int exit_code) {
return X_STATUS_SUCCESS; return X_STATUS_SUCCESS;
} }
X_STATUS XThread::PlatformTerminate(int exit_code) {
// TODO!
assert_always();
}
#endif // WIN32 #endif // WIN32
void XThread::Execute() { void XThread::Execute() {

View File

@ -103,6 +103,7 @@ class XThread : public XObject {
X_STATUS Create(); X_STATUS Create();
X_STATUS Exit(int exit_code); X_STATUS Exit(int exit_code);
X_STATUS Terminate(int exit_code);
virtual void Execute(); virtual void Execute();
@ -137,6 +138,7 @@ class XThread : public XObject {
X_STATUS PlatformCreate(); X_STATUS PlatformCreate();
void PlatformDestroy(); void PlatformDestroy();
X_STATUS PlatformExit(int exit_code); X_STATUS PlatformExit(int exit_code);
X_STATUS PlatformTerminate(int exit_code);
static void DeliverAPCs(void* data); static void DeliverAPCs(void* data);
void RundownAPCs(); void RundownAPCs();