add mutex functions to the API
[imager.git] / mutexpthr.c
... / ...
CommitLineData
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
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
28void
29i_mutex_destroy(i_mutex_t m) {
30 pthread_mutex_destroy(&(m->mutex));
31 myfree(m);
32}
33
34void
35i_mutex_lock(i_mutex_t m) {
36 pthread_mutex_lock(&(m->mutex));
37}
38
39void
40i_mutex_unlock(i_mutex_t m) {
41 pthread_mutex_unlock(&m->mutex);
42}