|
91 | 91 | #endif
|
92 | 92 |
|
93 | 93 |
|
94 |
| -#define LW_FLAG_HAS_WAITERS ((uint32) 1 << 30) |
95 |
| -#define LW_FLAG_RELEASE_OK ((uint32) 1 << 29) |
96 |
| -#define LW_FLAG_LOCKED ((uint32) 1 << 28) |
97 |
| - |
98 |
| -#define LW_VAL_EXCLUSIVE ((uint32) 1 << 24) |
| 94 | +#define LW_FLAG_HAS_WAITERS ((uint32) 1 << 31) |
| 95 | +#define LW_FLAG_RELEASE_OK ((uint32) 1 << 30) |
| 96 | +#define LW_FLAG_LOCKED ((uint32) 1 << 29) |
| 97 | +#define LW_FLAG_BITS 3 |
| 98 | +#define LW_FLAG_MASK (((1<<LW_FLAG_BITS)-1)<<(32-LW_FLAG_BITS)) |
| 99 | + |
| 100 | +/* assumes MAX_BACKENDS is a (power of 2) - 1, checked below */ |
| 101 | +#define LW_VAL_EXCLUSIVE (MAX_BACKENDS + 1) |
99 | 102 | #define LW_VAL_SHARED 1
|
100 | 103 |
|
101 |
| -#define LW_LOCK_MASK ((uint32) ((1 << 25)-1)) |
102 |
| -/* Must be greater than MAX_BACKENDS - which is 2^23-1, so we're fine. */ |
103 |
| -#define LW_SHARED_MASK ((uint32) ((1 << 24)-1)) |
| 104 | +/* already (power of 2)-1, i.e. suitable for a mask */ |
| 105 | +#define LW_SHARED_MASK MAX_BACKENDS |
| 106 | +#define LW_LOCK_MASK (MAX_BACKENDS | LW_VAL_EXCLUSIVE) |
| 107 | + |
| 108 | + |
| 109 | +StaticAssertDecl(((MAX_BACKENDS + 1) & MAX_BACKENDS) == 0, |
| 110 | + "MAX_BACKENDS + 1 needs to be a power of 2"); |
| 111 | + |
| 112 | +StaticAssertDecl((MAX_BACKENDS & LW_FLAG_MASK) == 0, |
| 113 | + "MAX_BACKENDS and LW_FLAG_MASK overlap"); |
104 | 114 |
|
105 |
| -StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS, |
106 |
| - "MAX_BACKENDS too big for lwlock.c"); |
| 115 | +StaticAssertDecl((LW_VAL_EXCLUSIVE & LW_FLAG_MASK) == 0, |
| 116 | + "LW_VAL_EXCLUSIVE and LW_FLAG_MASK overlap"); |
107 | 117 |
|
108 | 118 | /*
|
109 | 119 | * There are three sorts of LWLock "tranches":
|
|
0 commit comments