2017-04-05 00:15:04 +08:00
|
|
|
#ifndef _PERF_RWSEM_H
|
|
|
|
#define _PERF_RWSEM_H
|
|
|
|
|
|
|
|
#include <pthread.h>
|
2023-10-25 06:23:04 +08: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-05 00:15:04 +08:00
|
|
|
|
|
|
|
struct rw_semaphore {
|
2023-10-25 06:23:04 +08:00
|
|
|
#if RWS_ERRORCHECK
|
|
|
|
struct mutex mtx;
|
|
|
|
#else
|
2017-04-05 00:15:04 +08:00
|
|
|
pthread_rwlock_t lock;
|
2023-10-25 06:23:04 +08:00
|
|
|
#endif
|
2017-04-05 00:15:04 +08: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 */
|