1 /* SPDX-License-Identifier: GPL-2.0+ */
2 #ifndef _TOOLS__RWSEM_H
3 #define _TOOLS__RWSEM_H
11 static inline int init_rwsem(struct rw_semaphore
*sem
)
13 return pthread_rwlock_init(&sem
->lock
, NULL
);
16 static inline int exit_rwsem(struct rw_semaphore
*sem
)
18 return pthread_rwlock_destroy(&sem
->lock
);
21 static inline int down_read(struct rw_semaphore
*sem
)
23 return pthread_rwlock_rdlock(&sem
->lock
);
26 static inline int up_read(struct rw_semaphore
*sem
)
28 return pthread_rwlock_unlock(&sem
->lock
);
31 static inline int down_write(struct rw_semaphore
*sem
)
33 return pthread_rwlock_wrlock(&sem
->lock
);
36 static inline int up_write(struct rw_semaphore
*sem
)
38 return pthread_rwlock_unlock(&sem
->lock
);
41 #define down_read_nested(sem, subclass) down_read(sem)
42 #define down_write_nested(sem, subclass) down_write(sem)
44 #endif /* _TOOLS_RWSEM_H */