blob: 246afeed0675678e24d2535372be5d64d8793ad1 [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 Axboe8b4e9542013-03-21 10:05:07 -06006#define FIO_MUTEX_MAGIC 0x4d555445U
7#define FIO_RWLOCK_MAGIC 0x52574c4fU
8
Jens Axboecdd18ad2008-02-27 18:58:00 +01009struct fio_mutex {
Jens Axboe07739b52007-03-08 20:25:46 +010010 pthread_mutex_t lock;
11 pthread_cond_t cond;
Jens Axboe64d4d312008-03-03 10:36:27 +010012 int value;
Jens Axboe4d4e80f2008-03-04 10:18:56 +010013 int waiters;
Jens Axboe8b4e9542013-03-21 10:05:07 -060014 int magic;
Jens Axboe07739b52007-03-08 20:25:46 +010015};
16
Jens Axboed7df1d12013-03-20 19:57:01 -060017struct fio_rwlock {
18 pthread_rwlock_t lock;
Jens Axboe8b4e9542013-03-21 10:05:07 -060019 int magic;
Jens Axboed7df1d12013-03-20 19:57:01 -060020};
21
Jens Axboe521da522012-08-02 11:21:36 +020022enum {
23 FIO_MUTEX_LOCKED = 0,
24 FIO_MUTEX_UNLOCKED = 1,
25};
26
Jens Axboe72242052014-04-02 15:45:25 -060027extern int __fio_mutex_init(struct fio_mutex *, int);
Jens Axboecdd18ad2008-02-27 18:58:00 +010028extern struct fio_mutex *fio_mutex_init(int);
29extern void fio_mutex_remove(struct fio_mutex *);
Jens Axboed7df1d12013-03-20 19:57:01 -060030extern void fio_mutex_up(struct fio_mutex *);
Jens Axboeaf4bab52008-03-01 15:12:48 +010031extern void fio_mutex_down(struct fio_mutex *);
Jens Axboe72242052014-04-02 15:45:25 -060032extern int fio_mutex_down_trylock(struct fio_mutex *);
Jens Axboe656b1392009-07-01 23:02:10 +020033extern int fio_mutex_down_timeout(struct fio_mutex *, unsigned int);
Jens Axboe07739b52007-03-08 20:25:46 +010034
Jens Axboed7df1d12013-03-20 19:57:01 -060035extern void fio_rwlock_read(struct fio_rwlock *);
36extern void fio_rwlock_write(struct fio_rwlock *);
37extern void fio_rwlock_unlock(struct fio_rwlock *);
38extern struct fio_rwlock *fio_rwlock_init(void);
39extern void fio_rwlock_remove(struct fio_rwlock *);
Jens Axboe4d4e80f2008-03-04 10:18:56 +010040
Jens Axboe07739b52007-03-08 20:25:46 +010041#endif