2017-04-04 09:15:04 -07:00
|
|
|
#ifndef _PERF_RWSEM_H
|
|
|
|
#define _PERF_RWSEM_H
|
|
|
|
|
|
|
|
#include <pthread.h>
|
2023-10-24 15:23:04 -07:00
|
|
|
#include "mutex.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mutexes have additional error checking. Enable to use a mutex rather than a
|
|
|
|
* rwlock for debugging.
|
|
|
|
*/
|
|
|
|
#define RWS_ERRORCHECK 0
|
2017-04-04 09:15:04 -07:00
|
|
|
|
|
|
|
struct rw_semaphore {
|
2023-10-24 15:23:04 -07:00
|
|
|
#if RWS_ERRORCHECK
|
|
|
|
struct mutex mtx;
|
|
|
|
#else
|
2017-04-04 09:15:04 -07:00
|
|
|
pthread_rwlock_t lock;
|
2023-10-24 15:23:04 -07:00
|
|
|
#endif
|
2017-04-04 09:15:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
int init_rwsem(struct rw_semaphore *sem);
|
|
|
|
int exit_rwsem(struct rw_semaphore *sem);
|
|
|
|
|
|
|
|
int down_read(struct rw_semaphore *sem);
|
|
|
|
int up_read(struct rw_semaphore *sem);
|
|
|
|
|
|
|
|
int down_write(struct rw_semaphore *sem);
|
|
|
|
int up_write(struct rw_semaphore *sem);
|
|
|
|
|
|
|
|
#endif /* _PERF_RWSEM_H */
|