• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define FIO_RWLOCK_MAGIC	0x52574c4fU
9 
10 struct fio_mutex {
11 	pthread_mutex_t lock;
12 	pthread_cond_t cond;
13 	int value;
14 	int waiters;
15 	int magic;
16 };
17 
18 struct fio_rwlock {
19 	pthread_rwlock_t lock;
20 	int magic;
21 };
22 
23 enum {
24 	FIO_MUTEX_LOCKED	= 0,
25 	FIO_MUTEX_UNLOCKED	= 1,
26 };
27 
28 extern int __fio_mutex_init(struct fio_mutex *, int);
29 extern struct fio_mutex *fio_mutex_init(int);
30 extern void __fio_mutex_remove(struct fio_mutex *);
31 extern void fio_mutex_remove(struct fio_mutex *);
32 extern void fio_mutex_up(struct fio_mutex *);
33 extern void fio_mutex_down(struct fio_mutex *);
34 extern bool fio_mutex_down_trylock(struct fio_mutex *);
35 extern int fio_mutex_down_timeout(struct fio_mutex *, unsigned int);
36 
37 extern void fio_rwlock_read(struct fio_rwlock *);
38 extern void fio_rwlock_write(struct fio_rwlock *);
39 extern void fio_rwlock_unlock(struct fio_rwlock *);
40 extern struct fio_rwlock *fio_rwlock_init(void);
41 extern void fio_rwlock_remove(struct fio_rwlock *);
42 
43 extern int mutex_init_pshared(pthread_mutex_t *);
44 extern int cond_init_pshared(pthread_cond_t *);
45 extern int mutex_cond_init_pshared(pthread_mutex_t *, pthread_cond_t *);
46 
47 #endif
48