From da97a8802c45b888206cf1144fc00e98f51bdd9c Mon Sep 17 00:00:00 2001 From: Fenrir Date: Fri, 24 Feb 2017 01:09:57 -0700 Subject: [PATCH] Add threadDetach function --- libctru/include/3ds/thread.h | 6 ++++++ libctru/source/thread.c | 13 +++++++++++++ 2 files changed, 19 insertions(+) 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();