| 1 | #ifndef FIO_MUTEX_H |
| 2 | #define FIO_MUTEX_H |
| 3 | |
| 4 | #include <pthread.h> |
| 5 | #include "lib/types.h" |
| 6 | |
| 7 | #define FIO_MUTEX_MAGIC 0x4d555445U |
| 8 | |
| 9 | struct fio_mutex { |
| 10 | pthread_mutex_t lock; |
| 11 | pthread_cond_t cond; |
| 12 | int value; |
| 13 | int waiters; |
| 14 | int magic; |
| 15 | }; |
| 16 | |
| 17 | enum { |
| 18 | FIO_MUTEX_LOCKED = 0, |
| 19 | FIO_MUTEX_UNLOCKED = 1, |
| 20 | }; |
| 21 | |
| 22 | extern int __fio_mutex_init(struct fio_mutex *, int); |
| 23 | extern struct fio_mutex *fio_mutex_init(int); |
| 24 | extern void __fio_mutex_remove(struct fio_mutex *); |
| 25 | extern void fio_mutex_remove(struct fio_mutex *); |
| 26 | extern void fio_mutex_up(struct fio_mutex *); |
| 27 | extern void fio_mutex_down(struct fio_mutex *); |
| 28 | extern bool fio_mutex_down_trylock(struct fio_mutex *); |
| 29 | extern int fio_mutex_down_timeout(struct fio_mutex *, unsigned int); |
| 30 | |
| 31 | #endif |