Jens Axboe | 07739b5 | 2007-03-08 20:25:46 +0100 | [diff] [blame] | 1 | #ifndef FIO_MUTEX_H |
| 2 | #define FIO_MUTEX_H |
| 3 | |
| 4 | #include <pthread.h> |
| 5 | |
Jens Axboe | cdd18ad | 2008-02-27 18:58:00 +0100 | [diff] [blame] | 6 | struct fio_mutex { |
Jens Axboe | 07739b5 | 2007-03-08 20:25:46 +0100 | [diff] [blame] | 7 | pthread_mutex_t lock; |
| 8 | pthread_cond_t cond; |
Jens Axboe | 64d4d31 | 2008-03-03 10:36:27 +0100 | [diff] [blame] | 9 | int value; |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 10 | int waiters; |
Jens Axboe | 07739b5 | 2007-03-08 20:25:46 +0100 | [diff] [blame] | 11 | |
Jens Axboe | cdd18ad | 2008-02-27 18:58:00 +0100 | [diff] [blame] | 12 | int mutex_fd; |
Jens Axboe | 07739b5 | 2007-03-08 20:25:46 +0100 | [diff] [blame] | 13 | }; |
| 14 | |
Jens Axboe | cdd18ad | 2008-02-27 18:58:00 +0100 | [diff] [blame] | 15 | extern struct fio_mutex *fio_mutex_init(int); |
| 16 | extern void fio_mutex_remove(struct fio_mutex *); |
Jens Axboe | af4bab5 | 2008-03-01 15:12:48 +0100 | [diff] [blame] | 17 | extern void fio_mutex_down(struct fio_mutex *); |
Jens Axboe | 64d4d31 | 2008-03-03 10:36:27 +0100 | [diff] [blame] | 18 | extern void fio_mutex_down_read(struct fio_mutex *); |
| 19 | extern void fio_mutex_down_write(struct fio_mutex *); |
Jens Axboe | af4bab5 | 2008-03-01 15:12:48 +0100 | [diff] [blame] | 20 | extern void fio_mutex_up(struct fio_mutex *); |
Jens Axboe | 64d4d31 | 2008-03-03 10:36:27 +0100 | [diff] [blame] | 21 | extern void fio_mutex_up_read(struct fio_mutex *); |
| 22 | extern void fio_mutex_up_write(struct fio_mutex *); |
Jens Axboe | 07739b5 | 2007-03-08 20:25:46 +0100 | [diff] [blame] | 23 | |
Jens Axboe | 9c5b529 | 2008-03-03 11:08:19 +0100 | [diff] [blame] | 24 | static inline struct fio_mutex *fio_mutex_rw_init(void) |
| 25 | { |
| 26 | return fio_mutex_init(0); |
| 27 | } |
| 28 | |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 29 | static inline int fio_mutex_getval(struct fio_mutex *mutex) |
| 30 | { |
| 31 | return mutex->value; |
| 32 | } |
| 33 | |
Jens Axboe | 07739b5 | 2007-03-08 20:25:46 +0100 | [diff] [blame] | 34 | #endif |