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 munmap((void *) lock, sizeof(*lock));
34 struct fio_rwlock *fio_rwlock_init(void)
36 struct fio_rwlock *lock;
37 pthread_rwlockattr_t attr;
40 lock = (void *) mmap(NULL, sizeof(struct fio_rwlock),
41 PROT_READ | PROT_WRITE,
42 OS_MAP_ANON | MAP_SHARED, -1, 0);
43 if (lock == MAP_FAILED) {
44 perror("mmap rwlock");
49 lock->magic = FIO_RWLOCK_MAGIC;
51 ret = pthread_rwlockattr_init(&attr);
53 log_err("pthread_rwlockattr_init: %s\n", strerror(ret));
57 ret = pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
59 log_err("pthread_rwlockattr_setpshared: %s\n", strerror(ret));
63 ret = pthread_rwlock_init(&lock->lock, &attr);
65 ret = pthread_rwlock_init(&lock->lock, NULL);
69 log_err("pthread_rwlock_init: %s\n", strerror(ret));
73 pthread_rwlockattr_destroy(&attr);
77 pthread_rwlockattr_destroy(&attr);
80 fio_rwlock_remove(lock);