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 | 8b4e954 | 2013-03-21 10:05:07 -0600 | [diff] [blame] | 6 | #define FIO_MUTEX_MAGIC 0x4d555445U |
| 7 | #define FIO_RWLOCK_MAGIC 0x52574c4fU |
| 8 | |
Jens Axboe | cdd18ad | 2008-02-27 18:58:00 +0100 | [diff] [blame] | 9 | struct fio_mutex { |
Jens Axboe | 07739b5 | 2007-03-08 20:25:46 +0100 | [diff] [blame] | 10 | pthread_mutex_t lock; |
| 11 | pthread_cond_t cond; |
Jens Axboe | 64d4d31 | 2008-03-03 10:36:27 +0100 | [diff] [blame] | 12 | int value; |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 13 | int waiters; |
Jens Axboe | 8b4e954 | 2013-03-21 10:05:07 -0600 | [diff] [blame] | 14 | int magic; |
Jens Axboe | 07739b5 | 2007-03-08 20:25:46 +0100 | [diff] [blame] | 15 | }; |
| 16 | |
Jens Axboe | d7df1d1 | 2013-03-20 19:57:01 -0600 | [diff] [blame] | 17 | struct fio_rwlock { |
| 18 | pthread_rwlock_t lock; |
Jens Axboe | 8b4e954 | 2013-03-21 10:05:07 -0600 | [diff] [blame] | 19 | int magic; |
Jens Axboe | d7df1d1 | 2013-03-20 19:57:01 -0600 | [diff] [blame] | 20 | }; |
| 21 | |
Jens Axboe | 521da52 | 2012-08-02 11:21:36 +0200 | [diff] [blame] | 22 | enum { |
| 23 | FIO_MUTEX_LOCKED = 0, |
| 24 | FIO_MUTEX_UNLOCKED = 1, |
| 25 | }; |
| 26 | |
Jens Axboe | cdd18ad | 2008-02-27 18:58:00 +0100 | [diff] [blame] | 27 | extern struct fio_mutex *fio_mutex_init(int); |
| 28 | extern void fio_mutex_remove(struct fio_mutex *); |
Jens Axboe | d7df1d1 | 2013-03-20 19:57:01 -0600 | [diff] [blame] | 29 | extern void fio_mutex_up(struct fio_mutex *); |
Jens Axboe | af4bab5 | 2008-03-01 15:12:48 +0100 | [diff] [blame] | 30 | extern void fio_mutex_down(struct fio_mutex *); |
Jens Axboe | 656b139 | 2009-07-01 23:02:10 +0200 | [diff] [blame] | 31 | extern int fio_mutex_down_timeout(struct fio_mutex *, unsigned int); |
Jens Axboe | 07739b5 | 2007-03-08 20:25:46 +0100 | [diff] [blame] | 32 | |
Jens Axboe | d7df1d1 | 2013-03-20 19:57:01 -0600 | [diff] [blame] | 33 | extern void fio_rwlock_read(struct fio_rwlock *); |
| 34 | extern void fio_rwlock_write(struct fio_rwlock *); |
| 35 | extern void fio_rwlock_unlock(struct fio_rwlock *); |
| 36 | extern struct fio_rwlock *fio_rwlock_init(void); |
| 37 | extern void fio_rwlock_remove(struct fio_rwlock *); |
Jens Axboe | 4d4e80f | 2008-03-04 10:18:56 +0100 | [diff] [blame] | 38 | |
Jens Axboe | 07739b5 | 2007-03-08 20:25:46 +0100 | [diff] [blame] | 39 | #endif |