10 void fio_rwlock_write(struct fio_rwlock *lock)
12 assert(lock->magic == FIO_RWLOCK_MAGIC);
13 pthread_rwlock_wrlock(&lock->lock);
16 void fio_rwlock_read(struct fio_rwlock *lock)
18 assert(lock->magic == FIO_RWLOCK_MAGIC);
19 pthread_rwlock_rdlock(&lock->lock);
22 void fio_rwlock_unlock(struct fio_rwlock *lock)
24 assert(lock->magic == FIO_RWLOCK_MAGIC);
25 pthread_rwlock_unlock(&lock->lock);
28 void fio_rwlock_remove(struct fio_rwlock *lock)
30 assert(lock->magic == FIO_RWLOCK_MAGIC);
31 pthread_rwlock_destroy(&lock->lock);
32 munmap((void *) lock, sizeof(*lock));
35 struct fio_rwlock *fio_rwlock_init(void)
37 struct fio_rwlock *lock;
38 pthread_rwlockattr_t attr;
41 lock = (void *) mmap(NULL, sizeof(struct fio_rwlock),
42 PROT_READ | PROT_WRITE,
43 OS_MAP_ANON | MAP_SHARED, -1, 0);
44 if (lock == MAP_FAILED) {
45 perror("mmap rwlock");
50 lock->magic = FIO_RWLOCK_MAGIC;
52 ret = pthread_rwlockattr_init(&attr);
54 log_err("pthread_rwlockattr_init: %s\n", strerror(ret));
58 ret = pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
60 log_err("pthread_rwlockattr_setpshared: %s\n", strerror(ret));
64 ret = pthread_rwlock_init(&lock->lock, &attr);
66 ret = pthread_rwlock_init(&lock->lock, NULL);
70 log_err("pthread_rwlock_init: %s\n", strerror(ret));
74 pthread_rwlockattr_destroy(&attr);
78 pthread_rwlockattr_destroy(&attr);
81 fio_rwlock_remove(lock);