blob: ca5b7e8daeb428a32cece1b18f91f47e30d6828f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
/**
* @file rwlock_type.h
* @author Hanjie Wu (hanjiew)
* @author Devang Acharya (devanga)
* @brief rwlock structure
* @date 2023-02-22
*
*/
#ifndef RWLOCK_TYPE_H
#define RWLOCK_TYPE_H
#include <cond.h>
#include <mutex.h>
/**
* @brief indicates that the rwlock is unlocked
*/
#define RWLOCK_STATUS_UNLOCK 0
/**
* @brief indicates that the rwlock is locked by at least 1 reader
*/
#define RWLOCK_STATUS_READ 1
/**
* @brief indicates that the rwlock is locked by a writer
*/
#define RWLOCK_STATUS_WRITE 2
/**
* @brief rwlock structure
*/
typedef struct rwlock_s {
mutex_t status_lock; /* mutex to protect other structures */
int num_reader; /* number of readers holding this rwlock */
cond_t reader_cv; /* cv to wait for read availability */
cond_t writer_cv; /* cv to wait for write availability */
int status; /* status of this rwlock */
} rwlock_t;
#endif
|