ck_rw_cohort: Added neutral reader-writer lock

ck_pring
Brendon Scheinman 12 years ago
parent 21750b9321
commit f693a16253

@ -233,4 +233,71 @@
.wait_limit = 0 \
}
#define CK_RW_COHORT_NEUTRAL_NAME(N) ck_rw_cohort_neutral_##N
#define CK_RW_COHORT_NEUTRAL_INSTANCE(N) struct CK_RW_COHORT_NEUTRAL_NAME(N)
#define CK_RW_COHORT_NEUTRAL_INIT(N, RW, WL) ck_rw_cohort_neutral_##N##_init(RW, WL)
#define CK_RW_COHORT_NEUTRAL_READ_LOCK(N, RW, C, GC, LC) ck_rw_cohort_neutral_##N##_read_lock(RW, C, GC, LC)
#define CK_RW_COHORT_NEUTRAL_READ_UNLOCK(N, RW, C, GC, LC) ck_rw_cohort_neutral_##N##_read_unlock(RW)
#define CK_RW_COHORT_NEUTRAL_WRITE_LOCK(N, RW, C, GC, LC) ck_rw_cohort_neutral_##N##_write_lock(RW, C, GC, LC)
#define CK_RW_COHORT_NEUTRAL_WRITE_UNLOCK(N, RW, C, GC, LC) ck_rw_cohort_neutral_##N##_write_unlock(RW, C, GC, LC)
#define CK_RW_COHORT_NEUTRAL_DEFAULT_WAIT_LIMIT 1000
#define CK_RW_COHORT_NEUTRAL_PROTOTYPE(N) \
CK_RW_COHORT_NEUTRAL_INSTANCE(N) { \
unsigned int read_counter; \
}; \
\
CK_CC_INLINE static void \
ck_rw_cohort_neutral_##N##_init(CK_RW_COHORT_NEUTRAL_INSTANCE(N) *rw_cohort) \
{ \
rw_cohort->read_counter = 0; \
ck_pr_barrier(); \
return; \
} \
\
CK_CC_INLINE static void \
ck_rw_cohort_neutral_##N##_write_lock(CK_RW_COHORT_NEUTRAL_INSTANCE(N) *rw_cohort, \
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
void *local_context) \
{ \
CK_COHORT_LOCK(N, cohort, global_context, local_context); \
while (ck_pr_load_uint(&rw_cohort->read_counter) > 0) { \
ck_pr_stall(); \
} \
return; \
} \
\
CK_CC_INLINE static void \
ck_rw_cohort_neutral_##N##_write_unlock(CK_RW_COHORT_NEUTRAL_INSTANCE(N) *rw_cohort, \
CK_COHORT_INSTANCE(N) *cohort, void *global_context, void *local_context) \
{ \
(void)rw_cohort; \
CK_COHORT_UNLOCK(N, cohort, global_context, local_context); \
} \
\
CK_CC_INLINE static void \
ck_rw_cohort_neutral_##N##_read_lock(CK_RW_COHORT_NEUTRAL_INSTANCE(N) *rw_cohort, \
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
void *local_context) \
{ \
CK_COHORT_LOCK(N, cohort, global_context, local_context); \
ck_pr_inc_uint(&rw_cohort->read_counter); \
CK_COHORT_UNLOCK(N, cohort, global_context, local_context); \
\
return; \
} \
\
\
CK_CC_INLINE static void \
ck_rw_cohort_neutral_##N##_read_unlock(CK_RW_COHORT_NEUTRAL_INSTANCE(N) *cohort) \
{ \
ck_pr_dec_uint(&cohort->read_counter); \
}
#define CK_RW_COHORT_NEUTRAL_INITIALIZER { \
.read_counter = 0, \
}
#endif /* _CK_RW_COHORT_H */

@ -1,7 +1,6 @@
.PHONY: check clean distribution
#OBJECTS=ck_neutral ck_rp ck_wp
OBJECTS=ck_rp ck_wp
OBJECTS=ck_neutral ck_rp ck_wp
all: $(OBJECTS)

Loading…
Cancel
Save