commit d253905b46a95beb524fd2394ba30d3d45b16692 parent 9605ac2727af001549137090cdbf967137f65f91 Author: Michael Savage <mikejsavage@gmail.com> Date: Sat Aug 20 20:57:07 +0100 Add thread_cancel/thread_join to unix_thread.h Diffstat:
unix_thread.h | | | 17 | ++++++++++++++++- |
diff --git a/unix_thread.h b/unix_thread.h @@ -5,7 +5,7 @@ #include <pthread.h> #include <sys/syscall.h> -#include "platform_atomic.h" +#include "intrinsics.h" #define THREAD( f ) void * f( void * data ) typedef THREAD( ThreadCallback ); @@ -23,6 +23,7 @@ inline void thread_init( Thread * thread, ThreadCallback callback, void * data ) } inline u32 thread_getid() { + // TODO: make these casts explicit and checked #if defined( __linux__ ) return syscall( SYS_gettid ); #elif defined( __OpenBSD__ ) @@ -32,4 +33,18 @@ inline u32 thread_getid() { #endif } +inline void thread_cancel( Thread * thread ) { + int ok = pthread_cancel( thread->pthread ); + if( ok == -1 ) { + err( 1, "pthread_cancel failed" ); + } +} + +inline void thread_join( Thread * thread ) { + int ok = pthread_join( thread->pthread, NULL ); + if( ok == -1 ) { + err( 1, "pthread_join failed" ); + } +} + #endif // _UNIX_THREAD_H_