Add threadDetach function

This commit is contained in:
Fenrir 2017-02-24 01:09:57 -07:00 committed by Dave Murphy
parent c6c994ca60
commit da97a8802c
2 changed files with 19 additions and 0 deletions

View File

@ -65,6 +65,12 @@ void threadFree(Thread thread);
*/ */
Result threadJoin(Thread thread, u64 timeout_ns); 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. * @brief Retrieves the libctru thread handle of the current thread.
* @return libctru thread handle of the current thread, or NULL for the main thread * @return libctru thread handle of the current thread, or NULL for the main thread

View File

@ -107,6 +107,19 @@ Result threadJoin(Thread thread, u64 timeout_ns)
return svcWaitSynchronization(thread->handle, 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) Thread threadGetCurrent(void)
{ {
ThreadVars* tv = getThreadVars(); ThreadVars* tv = getThreadVars();