blob: 6fdf7c6dabceaa456d17f66040be3894c61556c8 [file] [log] [blame]
Jens Axboe07739b52007-03-08 20:25:46 +01001#ifndef FIO_MUTEX_H
2#define FIO_MUTEX_H
3
4#include <pthread.h>
5
Jens Axboecdd18ad2008-02-27 18:58:00 +01006struct fio_mutex {
Jens Axboe07739b52007-03-08 20:25:46 +01007 pthread_mutex_t lock;
8 pthread_cond_t cond;
Jens Axboe64d4d312008-03-03 10:36:27 +01009 int value;
Jens Axboe4d4e80f2008-03-04 10:18:56 +010010 int waiters;
Jens Axboe07739b52007-03-08 20:25:46 +010011};
12
Jens Axboe521da522012-08-02 11:21:36 +020013enum {
14 FIO_MUTEX_LOCKED = 0,
15 FIO_MUTEX_UNLOCKED = 1,
16};
17
Jens Axboecdd18ad2008-02-27 18:58:00 +010018extern struct fio_mutex *fio_mutex_init(int);
19extern void fio_mutex_remove(struct fio_mutex *);
Jens Axboeaf4bab52008-03-01 15:12:48 +010020extern void fio_mutex_down(struct fio_mutex *);
Jens Axboe656b1392009-07-01 23:02:10 +020021extern int fio_mutex_down_timeout(struct fio_mutex *, unsigned int);
Jens Axboe64d4d312008-03-03 10:36:27 +010022extern void fio_mutex_down_read(struct fio_mutex *);
23extern void fio_mutex_down_write(struct fio_mutex *);
Jens Axboeaf4bab52008-03-01 15:12:48 +010024extern void fio_mutex_up(struct fio_mutex *);
Jens Axboe64d4d312008-03-03 10:36:27 +010025extern void fio_mutex_up_read(struct fio_mutex *);
26extern void fio_mutex_up_write(struct fio_mutex *);
Jens Axboe07739b52007-03-08 20:25:46 +010027
Jens Axboe9c5b5292008-03-03 11:08:19 +010028static inline struct fio_mutex *fio_mutex_rw_init(void)
29{
30 return fio_mutex_init(0);
31}
32
Jens Axboe4d4e80f2008-03-04 10:18:56 +010033static inline int fio_mutex_getval(struct fio_mutex *mutex)
34{
35 return mutex->value;
36}
37
Jens Axboe07739b52007-03-08 20:25:46 +010038#endif