]> git.imager.perl.org - imager.git/blob - mutexpthr.c
re-work malloc_temp(), calloc_temp() to avoid SV overhead
[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 = malloc(sizeof(*m));
21   if (!m)
22     i_fatal(3, "Cannot allocate mutex object");
23   if (pthread_mutex_init(&m->mutex, NULL) != 0) {
24     i_fatal(3, "Error initializing mutex %d", errno);
25   }
26
27   return m;
28 }
29
30 void
31 i_mutex_destroy(i_mutex_t m) {
32   pthread_mutex_destroy(&(m->mutex));
33   free(m);
34 }
35
36 void
37 i_mutex_lock(i_mutex_t m) {
38   pthread_mutex_lock(&(m->mutex));
39 }
40
41 void
42 i_mutex_unlock(i_mutex_t m) {
43   pthread_mutex_unlock(&m->mutex);
44 }