1/* SPDX-License-Identifier: GPL-2.0+ */ 2#ifndef _TOOLS__RWSEM_H 3#define _TOOLS__RWSEM_H 4 5#include <pthread.h> 6 7struct rw_semaphore { 8 pthread_rwlock_t lock; 9}; 10 11static inline int init_rwsem(struct rw_semaphore *sem) 12{ 13 return pthread_rwlock_init(&sem->lock, NULL); 14} 15 16static inline int exit_rwsem(struct rw_semaphore *sem) 17{ 18 return pthread_rwlock_destroy(&sem->lock); 19} 20 21static inline int down_read(struct rw_semaphore *sem) 22{ 23 return pthread_rwlock_rdlock(&sem->lock); 24} 25 26static inline int up_read(struct rw_semaphore *sem) 27{ 28 return pthread_rwlock_unlock(&sem->lock); 29} 30 31static inline int down_write(struct rw_semaphore *sem) 32{ 33 return pthread_rwlock_wrlock(&sem->lock); 34} 35 36static inline int up_write(struct rw_semaphore *sem) 37{ 38 return pthread_rwlock_unlock(&sem->lock); 39} 40 41#define down_read_nested(sem, subclass) down_read(sem) 42#define down_write_nested(sem, subclass) down_write(sem) 43 44#endif /* _TOOLS_RWSEM_H */ 45