add mutex functions to the API
[imager.git] / mutexpthr.c
1 /*
2   pthreads mutexes
3 */
4
5 #include "imageri.h"
6
7 #include <pthread.h>
8 #include <errno.h>
9
10 /* documented in mutexwin.c */
11
12 struct i_mutex_tag {
13   pthread_mutex_t mutex;
14 };
15
16 i_mutex_t
17 i_mutex_new(void) {
18   i_mutex_t m;
19
20   m = mymalloc(sizeof(*m));
21   if (pthread_mutex_init(&m->mutex, NULL) != 0) {
22     i_fatal(3, "Error initializing mutex %d", errno);
23   }
24
25   return m;
26 }
27
28 void
29 i_mutex_destroy(i_mutex_t m) {
30   pthread_mutex_destroy(&(m->mutex));
31   myfree(m);
32 }
33
34 void
35 i_mutex_lock(i_mutex_t m) {
36   pthread_mutex_lock(&(m->mutex));
37 }
38
39 void
40 i_mutex_unlock(i_mutex_t m) {
41   pthread_mutex_unlock(&m->mutex);
42 }