eliminate use vars
[imager.git] / mutexpthr.c
CommitLineData
24c9233d
TC
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
12struct i_mutex_tag {
13 pthread_mutex_t mutex;
14};
15
16i_mutex_t
17i_mutex_new(void) {
18 i_mutex_t m;
19
a8b8be5b
TC
20 m = malloc(sizeof(*m));
21 if (!m)
22 i_fatal(3, "Cannot allocate mutex object");
24c9233d
TC
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
30void
31i_mutex_destroy(i_mutex_t m) {
32 pthread_mutex_destroy(&(m->mutex));
a8b8be5b 33 free(m);
24c9233d
TC
34}
35
36void
37i_mutex_lock(i_mutex_t m) {
38 pthread_mutex_lock(&(m->mutex));
39}
40
41void
42i_mutex_unlock(i_mutex_t m) {
43 pthread_mutex_unlock(&m->mutex);
44}