Add thread_exit and thread_yield
This commit is contained in:
parent
fe2590240b
commit
8dd0ffdb3b
|
@ -37,8 +37,20 @@ Thread thread_delete_handle(Thread th);
|
||||||
* Waits for a thread to exit
|
* Waits for a thread to exit
|
||||||
* @param th the thread to join
|
* @param th the thread to join
|
||||||
* @param result_ptr pointer to store the exit result or NULL
|
* @param result_ptr pointer to store the exit result or NULL
|
||||||
* @return bool on success, false on failure (errno may be set)
|
* @return true on success, false on failure (errno may be set)
|
||||||
*/
|
*/
|
||||||
bool thread_join(Thread th, ThreadResult *result_ptr);
|
bool thread_join(Thread th, ThreadResult *result_ptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Terminates current thread
|
||||||
|
* @param result exit result to return via thread_join
|
||||||
|
*/
|
||||||
|
void thread_exit(ThreadResult result) __attribute__((noreturn));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hints the OS to release CPU used by this thread
|
||||||
|
* @return true on success, false on failure (errno may be set)
|
||||||
|
*/
|
||||||
|
bool thread_yield();
|
||||||
|
|
||||||
#endif /* end of include guard: COMMON_UTIL_THREAD_H_ */
|
#endif /* end of include guard: COMMON_UTIL_THREAD_H_ */
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <sched.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
@ -114,3 +115,15 @@ thread_join(Thread th, ThreadResult *result_ptr)
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
thread_exit(ThreadResult result)
|
||||||
|
{
|
||||||
|
pthread_exit(result.pointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
thread_yield()
|
||||||
|
{
|
||||||
|
return !sched_yield();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue