diff --git a/libctru/include/3ds/thread.h b/libctru/include/3ds/thread.h index b1af28d..5a0f56a 100644 --- a/libctru/include/3ds/thread.h +++ b/libctru/include/3ds/thread.h @@ -65,6 +65,12 @@ void threadFree(Thread thread); */ Result threadJoin(Thread thread, u64 timeout_ns); +/** + * @brief Changes a thread's status from attached to detached. + * @param thread libctru thread handle + */ +void threadDetach(Thread thread); + /** * @brief Retrieves the libctru thread handle of the current thread. * @return libctru thread handle of the current thread, or NULL for the main thread diff --git a/libctru/source/thread.c b/libctru/source/thread.c index 8413f52..3c75b24 100644 --- a/libctru/source/thread.c +++ b/libctru/source/thread.c @@ -107,6 +107,19 @@ Result threadJoin(Thread thread, u64 timeout_ns) return svcWaitSynchronization(thread->handle, timeout_ns); } +void threadDetach(Thread thread) +{ + if (!thread || thread->detached) + return; + if (thread->finished) + { + threadFree(thread); + return; + } + thread->detached = true; + return; +} + Thread threadGetCurrent(void) { ThreadVars* tv = getThreadVars();