File tree 1 file changed +25
-1
lines changed
1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 30
30
typedef struct rw_lock_t {
31
31
gen_lock_t * lock ;
32
32
int w_flag ;
33
+ int sw_flag ;
33
34
int r_count ;
34
35
} rw_lock_t ;
35
36
@@ -113,7 +114,30 @@ inline static void lock_destroy_rw(rw_lock_t *_lock)
113
114
lock_release((_lock)->lock); \
114
115
} while (0)
115
116
116
- /* switch to writing access with lock previously acquired for reading
117
+ #define lock_start_sw_read (_lock ) \
118
+ do { \
119
+ __label__ again; \
120
+ again: \
121
+ lock_get((_lock)->lock); \
122
+ if ((_lock)->w_flag || (_lock)->sw_flag) { \
123
+ lock_release((_lock)->lock); \
124
+ usleep(LOCK_WAIT); \
125
+ goto again; \
126
+ } \
127
+ (_lock)->r_count++; \
128
+ (_lock)->sw_flag = 1; \
129
+ lock_release((_lock)->lock); \
130
+ } while (0)
131
+
132
+ #define lock_stop_sw_read (_lock ) \
133
+ do { \
134
+ lock_get((_lock)->lock); \
135
+ (_lock)->r_count--; \
136
+ lock_release((_lock)->lock); \
137
+ (_lock)->sw_flag = 0; \
138
+ } while (0)
139
+
140
+ /* switch to writing access with lock previously acquired for switchable reading
117
141
* note: switching back to reading is required before releasing the lock
118
142
*/
119
143
#define lock_switch_write (_lock , __old ) \
You can’t perform that action at this time.
0 commit comments