summaryrefslogtreecommitdiff
path: root/threading_pthread.c
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2009-08-28 21:49:53 +0200
committerGravatar waker <wakeroid@gmail.com>2009-08-28 21:49:53 +0200
commit4c41a6c6c9accea5854755bbb0f1a3476d31f8b2 (patch)
tree90438179ed3d0a7003f6756f01aafad8d22accac /threading_pthread.c
parent85e4f2aeaacb721aeabbcf1154b135985dc4b3b1 (diff)
added pthread_join support
Diffstat (limited to 'threading_pthread.c')
-rw-r--r--threading_pthread.c28
1 files changed, 21 insertions, 7 deletions
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 <stdlib.h>
#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));