blob: 17380de289a36cb7a76e34870db3c64efd7aa1a5 [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);
Jens Axboec1803422014-12-18 19:44:18 -070029extern void __fio_mutex_remove(struct fio_mutex *);
Jens Axboecdd18ad2008-02-27 18:58:00 +010030extern void fio_mutex_remove(struct fio_mutex *);
Jens Axboed7df1d12013-03-20 19:57:01 -060031extern void fio_mutex_up(struct fio_mutex *);
Jens Axboeaf4bab52008-03-01 15:12:48 +010032extern void fio_mutex_down(struct fio_mutex *);
Jens Axboe72242052014-04-02 15:45:25 -060033extern int fio_mutex_down_trylock(struct fio_mutex *);
Jens Axboe656b1392009-07-01 23:02:10 +020034extern int fio_mutex_down_timeout(struct fio_mutex *, unsigned int);
Jens Axboe07739b52007-03-08 20:25:46 +010035
Jens Axboed7df1d12013-03-20 19:57:01 -060036extern void fio_rwlock_read(struct fio_rwlock *);
37extern void fio_rwlock_write(struct fio_rwlock *);
38extern void fio_rwlock_unlock(struct fio_rwlock *);
39extern struct fio_rwlock *fio_rwlock_init(void);
40extern void fio_rwlock_remove(struct fio_rwlock *);
Jens Axboe4d4e80f2008-03-04 10:18:56 +010041
Jens Axboe07739b52007-03-08 20:25:46 +010042#endif