-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrwfutex.h
More file actions
61 lines (49 loc) · 1.17 KB
/
rwfutex.h
File metadata and controls
61 lines (49 loc) · 1.17 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Brandenburg Phase-Fair FIFO reader-writer lock
typedef volatile union {
struct {
uint16_t rin[1];
uint16_t rout[1];
uint16_t serving[1];
uint16_t ticket[1];
};
uint32_t rw[2];
} RWLock;
// define rin bits
#define PHID 0x1 // phase ID
#define PRES 0x2 // writer is present
#define MASK 0x3
#define RINC 0x4 // reader count increment
// Mutex based reader-writer lock
typedef enum {
FREE = 0,
LOCKED,
CONTESTED
} MutexState;
typedef struct {
volatile MutexState state[1];
} Mutex;
typedef struct {
Mutex xcl[1];
Mutex wrt[1];
uint16_t readers[1];
} RWLock2;
// mode & definition for lock implementation
enum {
QueRd = 1, // reader queue
QueWr = 2 // writer queue
} RWQueue;
// lite weight futex lock: Not phase-fair nor FIFO
typedef volatile union {
struct {
uint16_t read:1; // one or more readers are sleeping
uint16_t wrt:15; // count of writers sleeping
uint16_t xlock:1; // one writer has exclusive lock
uint16_t share:15; // count of readers holding lock
};
uint16_t shorts[2];
uint32_t longs[1];
} FutexLock;
#define READ 1
#define WRT 2
#define XCL 65536
#define SHARE (XCL * 2)