diff options
author | waker <wakeroid@gmail.com> | 2009-08-28 20:30:20 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2009-08-28 20:30:20 +0200 |
commit | f263abb8b777b61bcce7eee88716a137d0f880c3 (patch) | |
tree | 4e1b2c27affb8e9f3c27726b04b0fe9909cc919a /threading_pthread.c | |
parent | 81d1b50a3bd28099b784e5b2a14295e715a48d01 (diff) |
lastfm multithreading WIP
Diffstat (limited to 'threading_pthread.c')
-rw-r--r-- | threading_pthread.c | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/threading_pthread.c b/threading_pthread.c index ae8bf258..7bb3d50b 100644 --- a/threading_pthread.c +++ b/threading_pthread.c @@ -20,7 +20,8 @@ #include <stdlib.h> #include "threading.h" -void thread_start (void (*fn)(uintptr_t ctx), uintptr_t ctx) { +void +thread_start (void (*fn)(uintptr_t ctx), uintptr_t ctx) { pthread_t tid; pthread_attr_t attr; int s = pthread_attr_init (&attr); @@ -39,30 +40,71 @@ void thread_start (void (*fn)(uintptr_t ctx), uintptr_t ctx) { return; } } -uintptr_t mutex_create (void) { +uintptr_t +mutex_create (void) { pthread_mutex_t *mtx = malloc (sizeof (pthread_mutex_t)); if (pthread_mutex_init (mtx, NULL)) { printf ("pthread_mutex_init failed!\n"); } return (uintptr_t)mtx; } -void mutex_free (uintptr_t _mtx) { + +void +mutex_free (uintptr_t _mtx) { pthread_mutex_t *mtx = (pthread_mutex_t *)_mtx; mutex_lock (_mtx); mutex_unlock (_mtx); pthread_mutex_destroy (mtx); free (mtx); } -int mutex_lock (uintptr_t _mtx) { + +int +mutex_lock (uintptr_t _mtx) { pthread_mutex_t *mtx = (pthread_mutex_t *)_mtx; if (pthread_mutex_lock (mtx)) { printf ("pthread_mutex_lock failed\n"); } } -int mutex_unlock (uintptr_t _mtx) { + +int +mutex_unlock (uintptr_t _mtx) { pthread_mutex_t *mtx = (pthread_mutex_t *)_mtx; if (pthread_mutex_unlock (mtx)) { printf ("pthread_mutex_unlock failed\n"); }; } +uintptr_t +cond_create (void) { + pthread_cond_t *cond = malloc (sizeof (pthread_cond_t)); + pthread_cond_init (cond, NULL); + return (uintptr_t)cond; +} + +void +cond_free (uintptr_t c) { + if (c) { + pthread_cond_t *cond = (pthread_cond_t *)c; + pthread_cond_destroy (cond); + free (cond); + } +} + +int +cond_wait (uintptr_t c, uintptr_t m) { + pthread_cond_t *cond = (pthread_cond_t *)c; + pthread_mutex_t *mutex = (pthread_mutex_t *)m; + return pthread_cond_wait (cond, mutex); +} + +int +cond_signal (uintptr_t c) { + pthread_cond_t *cond = (pthread_cond_t *)c; + return pthread_cond_signal (cond); +} + +int +cond_broadcast (uintptr_t c) { + pthread_cond_t *cond = (pthread_cond_t *)c; + return pthread_cond_broadcast (cond); +} |