mutex: make 0/1 FIO_MUTEX_LOCKED and FIO_MUTEX_UNLOCKED
[fio.git] / mutex.h
CommitLineData
07739b57
JA
1#ifndef FIO_MUTEX_H
2#define FIO_MUTEX_H
3
4#include <pthread.h>
5
cdd18ad8 6struct fio_mutex {
07739b57
JA
7 pthread_mutex_t lock;
8 pthread_cond_t cond;
64d4d313 9 int value;
4d4e80f2 10 int waiters;
07739b57
JA
11};
12
521da527
JA
13enum {
14 FIO_MUTEX_LOCKED = 0,
15 FIO_MUTEX_UNLOCKED = 1,
16};
17
cdd18ad8
JA
18extern struct fio_mutex *fio_mutex_init(int);
19extern void fio_mutex_remove(struct fio_mutex *);
af4bab56 20extern void fio_mutex_down(struct fio_mutex *);
656b1393 21extern int fio_mutex_down_timeout(struct fio_mutex *, unsigned int);
64d4d313
JA
22extern void fio_mutex_down_read(struct fio_mutex *);
23extern void fio_mutex_down_write(struct fio_mutex *);
af4bab56 24extern void fio_mutex_up(struct fio_mutex *);
64d4d313
JA
25extern void fio_mutex_up_read(struct fio_mutex *);
26extern void fio_mutex_up_write(struct fio_mutex *);
07739b57 27
9c5b5290
JA
28static inline struct fio_mutex *fio_mutex_rw_init(void)
29{
30 return fio_mutex_init(0);
31}
32
4d4e80f2
JA
33static inline int fio_mutex_getval(struct fio_mutex *mutex)
34{
35 return mutex->value;
36}
37
07739b57 38#endif