Add the file sharing bits
[fio.git] / sem.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <stdlib.h>
5 #include <fcntl.h>
6 #include <pthread.h>
7 #include <sys/mman.h>
8 #include <assert.h>
9
10 #include "sem.h"
11 #include "smalloc.h"
12
13 void fio_sem_remove(struct fio_sem *sem)
14 {
15         sfree(sem);
16 }
17
18 struct fio_sem *fio_sem_init(int value)
19 {
20         struct fio_sem *sem;
21
22         sem = smalloc(sizeof(*sem));
23         if (!sem)
24                 return NULL;
25
26         sem->sem_val = value;
27
28         if (!sem_init(&sem->sem, 1, value))
29                 return sem;
30
31         perror("sem_init");
32         sfree(sem);
33         return NULL;
34 }
35
36 void fio_sem_down(struct fio_sem *sem)
37 {
38         sem_wait(&sem->sem);
39 }
40
41 void fio_sem_up(struct fio_sem *sem)
42 {
43         sem_post(&sem->sem);
44 }