From 4c41a6c6c9accea5854755bbb0f1a3476d31f8b2 Mon Sep 17 00:00:00 2001 From: waker Date: Fri, 28 Aug 2009 21:49:53 +0200 Subject: added pthread_join support --- threading_pthread.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'threading_pthread.c') diff --git a/threading_pthread.c b/threading_pthread.c index 7bb3d50b..0934ab4a 100644 --- a/threading_pthread.c +++ b/threading_pthread.c @@ -20,26 +20,40 @@ #include #include "threading.h" -void +int thread_start (void (*fn)(uintptr_t ctx), uintptr_t ctx) { pthread_t tid; pthread_attr_t attr; int s = pthread_attr_init (&attr); if (s) { - printf ("pthread_attr_init failed\n"); - return; + fprintf (stderr, "pthread_attr_init failed\n"); + return -1; } if (pthread_create (&tid, &attr, (void *(*)(void *))fn, (void*)ctx)) { - printf ("pthread_create failed\n"); - return; + fprintf (stderr, "pthread_create failed\n"); + return -1; } s = pthread_attr_destroy (&attr); if (s) { - printf ("pthread_attr_destroy failed\n"); - return; + fprintf (stderr, "pthread_attr_destroy failed\n"); + pthread_cancel (tid); + return -1; + } + return tid; +} + +int +thread_join (int tid) { + void *retval; + int s = pthread_join ((pthread_t)tid, &retval); + if (s) { + fprintf (stderr, "pthread_join failed\n"); + return -1; } + return 0; } + uintptr_t mutex_create (void) { pthread_mutex_t *mtx = malloc (sizeof (pthread_mutex_t)); -- cgit v1.2.3