|
|
|
@ -42,10 +42,14 @@
|
|
|
|
|
#define CK_RWCOHORT_WP_NAME(N) ck_rwcohort_wp_##N
|
|
|
|
|
#define CK_RWCOHORT_WP_INSTANCE(N) struct CK_RWCOHORT_WP_NAME(N)
|
|
|
|
|
#define CK_RWCOHORT_WP_INIT(N, RW, WL) ck_rwcohort_wp_##N##_init(RW, WL)
|
|
|
|
|
#define CK_RWCOHORT_WP_READ_LOCK(N, RW, C, GC, LC) ck_rwcohort_wp_##N##_read_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_WP_READ_UNLOCK(N, RW, C, GC, LC) ck_rwcohort_wp_##N##_read_unlock(RW)
|
|
|
|
|
#define CK_RWCOHORT_WP_WRITE_LOCK(N, RW, C, GC, LC) ck_rwcohort_wp_##N##_write_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_WP_WRITE_UNLOCK(N, RW, C, GC, LC) ck_rwcohort_wp_##N##_write_unlock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_WP_READ_LOCK(N, RW, C, GC, LC) \
|
|
|
|
|
ck_rwcohort_wp_##N##_read_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_WP_READ_UNLOCK(N, RW, C, GC, LC) \
|
|
|
|
|
ck_rwcohort_wp_##N##_read_unlock(RW)
|
|
|
|
|
#define CK_RWCOHORT_WP_WRITE_LOCK(N, RW, C, GC, LC) \
|
|
|
|
|
ck_rwcohort_wp_##N##_write_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_WP_WRITE_UNLOCK(N, RW, C, GC, LC) \
|
|
|
|
|
ck_rwcohort_wp_##N##_write_unlock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_WP_DEFAULT_WAIT_LIMIT 1000
|
|
|
|
|
|
|
|
|
|
#define CK_RWCOHORT_WP_PROTOTYPE(N) \
|
|
|
|
@ -58,6 +62,7 @@
|
|
|
|
|
ck_rwcohort_wp_##N##_init(CK_RWCOHORT_WP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
unsigned int wait_limit) \
|
|
|
|
|
{ \
|
|
|
|
|
\
|
|
|
|
|
rw_cohort->read_counter = 0; \
|
|
|
|
|
rw_cohort->write_barrier = 0; \
|
|
|
|
|
rw_cohort->wait_limit = wait_limit; \
|
|
|
|
@ -69,15 +74,14 @@
|
|
|
|
|
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
|
|
|
|
|
void *local_context) \
|
|
|
|
|
{ \
|
|
|
|
|
while (ck_pr_load_uint(&rw_cohort->write_barrier) > 0) { \
|
|
|
|
|
\
|
|
|
|
|
while (ck_pr_load_uint(&rw_cohort->write_barrier) > 0) \
|
|
|
|
|
ck_pr_stall(); \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
CK_COHORT_LOCK(N, cohort, global_context, local_context); \
|
|
|
|
|
\
|
|
|
|
|
while (ck_pr_load_uint(&rw_cohort->read_counter) > 0) { \
|
|
|
|
|
while (ck_pr_load_uint(&rw_cohort->read_counter) > 0) \
|
|
|
|
|
ck_pr_stall(); \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
return; \
|
|
|
|
|
} \
|
|
|
|
@ -86,6 +90,7 @@
|
|
|
|
|
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
|
|
|
|
|
void *local_context) \
|
|
|
|
|
{ \
|
|
|
|
|
\
|
|
|
|
|
(void)rw_cohort; \
|
|
|
|
|
CK_COHORT_UNLOCK(N, cohort, global_context, local_context); \
|
|
|
|
|
return; \
|
|
|
|
@ -100,29 +105,31 @@
|
|
|
|
|
\
|
|
|
|
|
for (;;) { \
|
|
|
|
|
ck_pr_inc_uint(&rw_cohort->read_counter); \
|
|
|
|
|
if (CK_COHORT_LOCKED(N, cohort, global_context, local_context) == false) {\
|
|
|
|
|
if (CK_COHORT_LOCKED(N, cohort, global_context, \
|
|
|
|
|
local_context) == false) \
|
|
|
|
|
break; \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
ck_pr_dec_uint(&rw_cohort->read_counter); \
|
|
|
|
|
while (CK_COHORT_LOCKED(N, cohort, global_context, local_context) == true) {\
|
|
|
|
|
while (CK_COHORT_LOCKED(N, cohort, global_context, \
|
|
|
|
|
local_context) == true) { \
|
|
|
|
|
ck_pr_stall(); \
|
|
|
|
|
if (++wait_count > rw_cohort->wait_limit && raised == false) { \
|
|
|
|
|
if (++wait_count > rw_cohort->wait_limit && \
|
|
|
|
|
raised == false) { \
|
|
|
|
|
ck_pr_inc_uint(&rw_cohort->write_barrier); \
|
|
|
|
|
raised = true; \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
if (raised == true) { \
|
|
|
|
|
if (raised == true) \
|
|
|
|
|
ck_pr_dec_uint(&rw_cohort->write_barrier); \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
return; \
|
|
|
|
|
} \
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rwcohort_wp_##N##_read_unlock(CK_RWCOHORT_WP_INSTANCE(N) *cohort) \
|
|
|
|
|
{ \
|
|
|
|
|
\
|
|
|
|
|
ck_pr_dec_uint(&cohort->read_counter); \
|
|
|
|
|
return; \
|
|
|
|
|
}
|
|
|
|
@ -133,14 +140,17 @@
|
|
|
|
|
.wait_limit = 0 \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define CK_RWCOHORT_RP_NAME(N) ck_rwcohort_rp_##N
|
|
|
|
|
#define CK_RWCOHORT_RP_INSTANCE(N) struct CK_RWCOHORT_RP_NAME(N)
|
|
|
|
|
#define CK_RWCOHORT_RP_INIT(N, RW, WL) ck_rwcohort_rp_##N##_init(RW, WL)
|
|
|
|
|
#define CK_RWCOHORT_RP_READ_LOCK(N, RW, C, GC, LC) ck_rwcohort_rp_##N##_read_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_RP_READ_UNLOCK(N, RW, C, GC, LC) ck_rwcohort_rp_##N##_read_unlock(RW)
|
|
|
|
|
#define CK_RWCOHORT_RP_WRITE_LOCK(N, RW, C, GC, LC) ck_rwcohort_rp_##N##_write_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_RP_WRITE_UNLOCK(N, RW, C, GC, LC) ck_rwcohort_rp_##N##_write_unlock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_RP_READ_LOCK(N, RW, C, GC, LC) \
|
|
|
|
|
ck_rwcohort_rp_##N##_read_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_RP_READ_UNLOCK(N, RW, C, GC, LC) \
|
|
|
|
|
ck_rwcohort_rp_##N##_read_unlock(RW)
|
|
|
|
|
#define CK_RWCOHORT_RP_WRITE_LOCK(N, RW, C, GC, LC) \
|
|
|
|
|
ck_rwcohort_rp_##N##_write_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_RP_WRITE_UNLOCK(N, RW, C, GC, LC) \
|
|
|
|
|
ck_rwcohort_rp_##N##_write_unlock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_RP_DEFAULT_WAIT_LIMIT 1000
|
|
|
|
|
|
|
|
|
|
#define CK_RWCOHORT_RP_PROTOTYPE(N) \
|
|
|
|
@ -153,6 +163,7 @@
|
|
|
|
|
ck_rwcohort_rp_##N##_init(CK_RWCOHORT_RP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
unsigned int wait_limit) \
|
|
|
|
|
{ \
|
|
|
|
|
\
|
|
|
|
|
rw_cohort->read_counter = 0; \
|
|
|
|
|
rw_cohort->read_barrier = 0; \
|
|
|
|
|
rw_cohort->wait_limit = wait_limit; \
|
|
|
|
@ -169,23 +180,22 @@
|
|
|
|
|
\
|
|
|
|
|
for (;;) { \
|
|
|
|
|
CK_COHORT_LOCK(N, cohort, global_context, local_context); \
|
|
|
|
|
if (ck_pr_load_uint(&rw_cohort->read_counter) == 0) { \
|
|
|
|
|
if (ck_pr_load_uint(&rw_cohort->read_counter) == 0) \
|
|
|
|
|
break; \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
CK_COHORT_UNLOCK(N, cohort, global_context, local_context); \
|
|
|
|
|
while (ck_pr_load_uint(&rw_cohort->read_counter) > 0) { \
|
|
|
|
|
ck_pr_stall(); \
|
|
|
|
|
if (++wait_count > rw_cohort->wait_limit && raised == false) { \
|
|
|
|
|
if (++wait_count > rw_cohort->wait_limit && \
|
|
|
|
|
raised == false) { \
|
|
|
|
|
ck_pr_inc_uint(&rw_cohort->read_barrier); \
|
|
|
|
|
raised = true; \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
if (raised == true) { \
|
|
|
|
|
if (raised == true) \
|
|
|
|
|
ck_pr_dec_uint(&rw_cohort->read_barrier); \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
return; \
|
|
|
|
|
} \
|
|
|
|
@ -193,6 +203,7 @@
|
|
|
|
|
ck_rwcohort_rp_##N##_write_unlock(CK_RWCOHORT_RP_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); \
|
|
|
|
|
return; \
|
|
|
|
@ -202,20 +213,21 @@
|
|
|
|
|
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
|
|
|
|
|
void *local_context) \
|
|
|
|
|
{ \
|
|
|
|
|
while (ck_pr_load_uint(&rw_cohort->read_barrier) > 0) { \
|
|
|
|
|
\
|
|
|
|
|
while (ck_pr_load_uint(&rw_cohort->read_barrier) > 0) \
|
|
|
|
|
ck_pr_stall(); \
|
|
|
|
|
} \
|
|
|
|
|
ck_pr_inc_uint(&rw_cohort->read_counter); \
|
|
|
|
|
\
|
|
|
|
|
while (CK_COHORT_LOCKED(N, cohort, global_context, local_context) == true) { \
|
|
|
|
|
while (CK_COHORT_LOCKED(N, cohort, global_context, \
|
|
|
|
|
local_context) == true) \
|
|
|
|
|
ck_pr_stall(); \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
return; \
|
|
|
|
|
} \
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rwcohort_rp_##N##_read_unlock(CK_RWCOHORT_RP_INSTANCE(N) *cohort) \
|
|
|
|
|
{ \
|
|
|
|
|
\
|
|
|
|
|
ck_pr_dec_uint(&cohort->read_counter); \
|
|
|
|
|
return; \
|
|
|
|
|
}
|
|
|
|
@ -226,14 +238,17 @@
|
|
|
|
|
.wait_limit = 0 \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_NAME(N) ck_rwcohort_neutral_##N
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_INSTANCE(N) struct CK_RWCOHORT_NEUTRAL_NAME(N)
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_INIT(N, RW) ck_rwcohort_neutral_##N##_init(RW)
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_READ_LOCK(N, RW, C, GC, LC) ck_rwcohort_neutral_##N##_read_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_READ_UNLOCK(N, RW, C, GC, LC) ck_rwcohort_neutral_##N##_read_unlock(RW)
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_WRITE_LOCK(N, RW, C, GC, LC) ck_rwcohort_neutral_##N##_write_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_WRITE_UNLOCK(N, RW, C, GC, LC) ck_rwcohort_neutral_##N##_write_unlock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_READ_LOCK(N, RW, C, GC, LC) \
|
|
|
|
|
ck_rwcohort_neutral_##N##_read_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_READ_UNLOCK(N, RW, C, GC, LC) \
|
|
|
|
|
ck_rwcohort_neutral_##N##_read_unlock(RW)
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_WRITE_LOCK(N, RW, C, GC, LC) \
|
|
|
|
|
ck_rwcohort_neutral_##N##_write_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_WRITE_UNLOCK(N, RW, C, GC, LC) \
|
|
|
|
|
ck_rwcohort_neutral_##N##_write_unlock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_DEFAULT_WAIT_LIMIT 1000
|
|
|
|
|
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_PROTOTYPE(N) \
|
|
|
|
@ -243,6 +258,7 @@
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rwcohort_neutral_##N##_init(CK_RWCOHORT_NEUTRAL_INSTANCE(N) *rw_cohort) \
|
|
|
|
|
{ \
|
|
|
|
|
\
|
|
|
|
|
rw_cohort->read_counter = 0; \
|
|
|
|
|
ck_pr_barrier(); \
|
|
|
|
|
return; \
|
|
|
|
@ -252,6 +268,7 @@
|
|
|
|
|
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(); \
|
|
|
|
@ -262,6 +279,7 @@
|
|
|
|
|
ck_rwcohort_neutral_##N##_write_unlock(CK_RWCOHORT_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); \
|
|
|
|
|
return; \
|
|
|
|
@ -271,15 +289,16 @@
|
|
|
|
|
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_rwcohort_neutral_##N##_read_unlock(CK_RWCOHORT_NEUTRAL_INSTANCE(N) *cohort) \
|
|
|
|
|
{ \
|
|
|
|
|
\
|
|
|
|
|
ck_pr_dec_uint(&cohort->read_counter); \
|
|
|
|
|
return; \
|
|
|
|
|
}
|
|
|
|
@ -288,5 +307,5 @@
|
|
|
|
|
.read_counter = 0, \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _CK_RWCOHORT_H */
|
|
|
|
|
|
|
|
|
|