diff --git a/src/common/util/thread.h b/src/common/util/thread.h index cbbe00e..7cc1977 100644 --- a/src/common/util/thread.h +++ b/src/common/util/thread.h @@ -37,8 +37,20 @@ Thread thread_delete_handle(Thread th); * Waits for a thread to exit * @param th the thread to join * @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); +/** + * 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_ */ diff --git a/src/common/util/thread.posix.c b/src/common/util/thread.posix.c index bdaa1b1..249da04 100644 --- a/src/common/util/thread.posix.c +++ b/src/common/util/thread.posix.c @@ -1,6 +1,7 @@ #include "thread.h" #include +#include #include #include @@ -114,3 +115,15 @@ thread_join(Thread th, ThreadResult *result_ptr) } return true; } + +void +thread_exit(ThreadResult result) +{ + pthread_exit(result.pointer); +} + +bool +thread_yield() +{ + return !sched_yield(); +}