blob: 54009bae4ae081094172da149814dcea6e4e7eec [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>
Elliott Hugheseda3a602017-05-19 18:53:02 -07005#include "lib/types.h"
Jens Axboe07739b52007-03-08 20:25:46 +01006
Jens Axboe8b4e9542013-03-21 10:05:07 -06007#define FIO_MUTEX_MAGIC 0x4d555445U
8#define FIO_RWLOCK_MAGIC 0x52574c4fU
9
Jens Axboecdd18ad2008-02-27 18:58:00 +010010struct fio_mutex {
Jens Axboe07739b52007-03-08 20:25:46 +010011 pthread_mutex_t lock;
12 pthread_cond_t cond;
Jens Axboe64d4d312008-03-03 10:36:27 +010013 int value;
Jens Axboe4d4e80f2008-03-04 10:18:56 +010014 int waiters;
Jens Axboe8b4e9542013-03-21 10:05:07 -060015 int magic;
Jens Axboe07739b52007-03-08 20:25:46 +010016};
17
Jens Axboed7df1d12013-03-20 19:57:01 -060018struct fio_rwlock {
19 pthread_rwlock_t lock;
Jens Axboe8b4e9542013-03-21 10:05:07 -060020 int magic;
Jens Axboed7df1d12013-03-20 19:57:01 -060021};
22
Jens Axboe521da522012-08-02 11:21:36 +020023enum {
24 FIO_MUTEX_LOCKED = 0,
25 FIO_MUTEX_UNLOCKED = 1,
26};
27
Jens Axboe72242052014-04-02 15:45:25 -060028extern int __fio_mutex_init(struct fio_mutex *, int);
Jens Axboecdd18ad2008-02-27 18:58:00 +010029extern struct fio_mutex *fio_mutex_init(int);
Jens Axboec1803422014-12-18 19:44:18 -070030extern void __fio_mutex_remove(struct fio_mutex *);
Jens Axboecdd18ad2008-02-27 18:58:00 +010031extern void fio_mutex_remove(struct fio_mutex *);
Jens Axboed7df1d12013-03-20 19:57:01 -060032extern void fio_mutex_up(struct fio_mutex *);
Jens Axboeaf4bab52008-03-01 15:12:48 +010033extern void fio_mutex_down(struct fio_mutex *);
Elliott Hugheseda3a602017-05-19 18:53:02 -070034extern bool fio_mutex_down_trylock(struct fio_mutex *);
Jens Axboe656b1392009-07-01 23:02:10 +020035extern int fio_mutex_down_timeout(struct fio_mutex *, unsigned int);
Jens Axboe07739b52007-03-08 20:25:46 +010036
Jens Axboed7df1d12013-03-20 19:57:01 -060037extern void fio_rwlock_read(struct fio_rwlock *);
38extern void fio_rwlock_write(struct fio_rwlock *);
39extern void fio_rwlock_unlock(struct fio_rwlock *);
40extern struct fio_rwlock *fio_rwlock_init(void);
41extern void fio_rwlock_remove(struct fio_rwlock *);
Jens Axboe4d4e80f2008-03-04 10:18:56 +010042
Elliott Hugheseda3a602017-05-19 18:53:02 -070043extern int mutex_init_pshared(pthread_mutex_t *);
44extern int cond_init_pshared(pthread_cond_t *);
45extern int mutex_cond_init_pshared(pthread_mutex_t *, pthread_cond_t *);
46
Jens Axboe07739b52007-03-08 20:25:46 +010047#endif