blob: 4f3486df7a3b01163515cd548678445d7e40b924 [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 Axboecdd18ad2008-02-27 18:58:00 +010027extern struct fio_mutex *fio_mutex_init(int);
28extern void fio_mutex_remove(struct fio_mutex *);
Jens Axboed7df1d12013-03-20 19:57:01 -060029extern void fio_mutex_up(struct fio_mutex *);
Jens Axboeaf4bab52008-03-01 15:12:48 +010030extern void fio_mutex_down(struct fio_mutex *);
Jens Axboe656b1392009-07-01 23:02:10 +020031extern int fio_mutex_down_timeout(struct fio_mutex *, unsigned int);
Jens Axboe07739b52007-03-08 20:25:46 +010032
Jens Axboed7df1d12013-03-20 19:57:01 -060033extern void fio_rwlock_read(struct fio_rwlock *);
34extern void fio_rwlock_write(struct fio_rwlock *);
35extern void fio_rwlock_unlock(struct fio_rwlock *);
36extern struct fio_rwlock *fio_rwlock_init(void);
37extern void fio_rwlock_remove(struct fio_rwlock *);
Jens Axboe4d4e80f2008-03-04 10:18:56 +010038
Jens Axboe07739b52007-03-08 20:25:46 +010039#endif