diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2010-02-11 20:03:10 +0100 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2010-02-11 20:03:10 +0100 |
commit | 06698504cafb9d3b87674c51bbd49dbbb6a54db0 (patch) | |
tree | 24934f001c2951e2151411693bec178717686a0d /threading_pthread.c | |
parent | 70fc72b7d985394517d3d84c3c160c3476adaf32 (diff) |
playlist thread-safety measures
Diffstat (limited to 'threading_pthread.c')
-rw-r--r-- | threading_pthread.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/threading_pthread.c b/threading_pthread.c index 25bc0026..c3e4e8fb 100644 --- a/threading_pthread.c +++ b/threading_pthread.c @@ -60,11 +60,30 @@ thread_join (intptr_t tid) { uintptr_t mutex_create (void) { pthread_mutex_t *mtx = malloc (sizeof (pthread_mutex_t)); - int err = pthread_mutex_init (mtx, NULL); + pthread_mutexattr_t attr = {0}; + pthread_mutexattr_init (&attr); + pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_NORMAL); + int err = pthread_mutex_init (mtx, &attr); if (err != 0) { fprintf (stderr, "pthread_mutex_init failed: %s\n", strerror (err)); return 0; } + pthread_mutexattr_destroy (&attr); + return (uintptr_t)mtx; +} + +uintptr_t +mutex_create_recursive (void) { + pthread_mutex_t *mtx = malloc (sizeof (pthread_mutex_t)); + pthread_mutexattr_t attr = {0}; + pthread_mutexattr_init (&attr); + pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); + int err = pthread_mutex_init (mtx, &attr); + if (err != 0) { + fprintf (stderr, "pthread_mutex_init failed: %s\n", strerror (err)); + return 0; + } + pthread_mutexattr_destroy (&attr); return (uintptr_t)mtx; } |