-
Notifications
You must be signed in to change notification settings - Fork 0
/
_rw_locks.h
21 lines (19 loc) · 889 Bytes
/
_rw_locks.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef RW_LOCK
#define RW_LOCK
#include <pthread.h>
struct rw_lock_t {
int readers; /* readers that have locked the variable */
int writers; /* writers that have locked the variable */
pthread_mutex_t WriterConditionMutex; /* A mutex for the condition the writers use */
pthread_mutex_t WriterMutex; /* A mutex that ensures that only one writer is actually writing at each point */
pthread_cond_t WriterCondition; /* The condition that wakes all the readers */
pthread_mutex_t ReaderConditionMutex; /* A mutex for the condition the readers use */
pthread_cond_t ReaderCondition; /* The condition that wakes all the writers */
};
int rw_init(struct rw_lock_t *rw);
int rw_destroy(struct rw_lock_t *rw);
int rw_readlock(struct rw_lock_t *rw);
int rw_readunlock(struct rw_lock_t *rw);
int rw_writelock(struct rw_lock_t *rw);
int rw_writeunlock(struct rw_lock_t *rw);
#endif