|
|
|
@ -25,8 +25,8 @@
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _CK_RW_COHORT_H
|
|
|
|
|
#define _CK_RW_COHORT_H
|
|
|
|
|
#ifndef _CK_RWCOHORT_H
|
|
|
|
|
#define _CK_RWCOHORT_H
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This is an implementation of NUMA-aware reader-writer locks as described in:
|
|
|
|
@ -39,24 +39,24 @@
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <ck_cohort.h>
|
|
|
|
|
|
|
|
|
|
#define CK_RW_COHORT_WP_NAME(N) ck_rw_cohort_wp_##N
|
|
|
|
|
#define CK_RW_COHORT_WP_INSTANCE(N) struct CK_RW_COHORT_WP_NAME(N)
|
|
|
|
|
#define CK_RW_COHORT_WP_INIT(N, RW, WL) ck_rw_cohort_wp_##N##_init(RW, WL)
|
|
|
|
|
#define CK_RW_COHORT_WP_READ_LOCK(N, RW, C, GC, LC) ck_rw_cohort_wp_##N##_read_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RW_COHORT_WP_READ_UNLOCK(N, RW, C, GC, LC) ck_rw_cohort_wp_##N##_read_unlock(RW)
|
|
|
|
|
#define CK_RW_COHORT_WP_WRITE_LOCK(N, RW, C, GC, LC) ck_rw_cohort_wp_##N##_write_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RW_COHORT_WP_WRITE_UNLOCK(N, RW, C, GC, LC) ck_rw_cohort_wp_##N##_write_unlock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RW_COHORT_WP_DEFAULT_WAIT_LIMIT 1000
|
|
|
|
|
#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_DEFAULT_WAIT_LIMIT 1000
|
|
|
|
|
|
|
|
|
|
#define CK_RW_COHORT_WP_PROTOTYPE(N) \
|
|
|
|
|
CK_RW_COHORT_WP_INSTANCE(N) { \
|
|
|
|
|
#define CK_RWCOHORT_WP_PROTOTYPE(N) \
|
|
|
|
|
CK_RWCOHORT_WP_INSTANCE(N) { \
|
|
|
|
|
unsigned int read_counter; \
|
|
|
|
|
unsigned int write_barrier; \
|
|
|
|
|
unsigned int wait_limit; \
|
|
|
|
|
}; \
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_wp_##N##_init(CK_RW_COHORT_WP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
ck_rwcohort_wp_##N##_init(CK_RWCOHORT_WP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
unsigned int wait_limit) \
|
|
|
|
|
{ \
|
|
|
|
|
rw_cohort->read_counter = 0; \
|
|
|
|
@ -67,7 +67,7 @@
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_wp_##N##_write_lock(CK_RW_COHORT_WP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
ck_rwcohort_wp_##N##_write_lock(CK_RWCOHORT_WP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
|
|
|
|
|
void *local_context) \
|
|
|
|
|
{ \
|
|
|
|
@ -85,7 +85,7 @@
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_wp_##N##_write_unlock(CK_RW_COHORT_WP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
ck_rwcohort_wp_##N##_write_unlock(CK_RWCOHORT_WP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
|
|
|
|
|
void *local_context) \
|
|
|
|
|
{ \
|
|
|
|
@ -94,7 +94,7 @@
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_wp_##N##_read_lock(CK_RW_COHORT_WP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
ck_rwcohort_wp_##N##_read_lock(CK_RWCOHORT_WP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
|
|
|
|
|
void *local_context) \
|
|
|
|
|
{ \
|
|
|
|
@ -125,36 +125,36 @@
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_wp_##N##_read_unlock(CK_RW_COHORT_WP_INSTANCE(N) *cohort) \
|
|
|
|
|
ck_rwcohort_wp_##N##_read_unlock(CK_RWCOHORT_WP_INSTANCE(N) *cohort) \
|
|
|
|
|
{ \
|
|
|
|
|
ck_pr_dec_uint(&cohort->read_counter); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define CK_RW_COHORT_WP_INITIALIZER { \
|
|
|
|
|
#define CK_RWCOHORT_WP_INITIALIZER { \
|
|
|
|
|
.read_counter = 0, \
|
|
|
|
|
.write_barrier = 0, \
|
|
|
|
|
.wait_limit = 0 \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define CK_RW_COHORT_RP_NAME(N) ck_rw_cohort_rp_##N
|
|
|
|
|
#define CK_RW_COHORT_RP_INSTANCE(N) struct CK_RW_COHORT_RP_NAME(N)
|
|
|
|
|
#define CK_RW_COHORT_RP_INIT(N, RW, WL) ck_rw_cohort_rp_##N##_init(RW, WL)
|
|
|
|
|
#define CK_RW_COHORT_RP_READ_LOCK(N, RW, C, GC, LC) ck_rw_cohort_rp_##N##_read_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RW_COHORT_RP_READ_UNLOCK(N, RW, C, GC, LC) ck_rw_cohort_rp_##N##_read_unlock(RW)
|
|
|
|
|
#define CK_RW_COHORT_RP_WRITE_LOCK(N, RW, C, GC, LC) ck_rw_cohort_rp_##N##_write_lock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RW_COHORT_RP_WRITE_UNLOCK(N, RW, C, GC, LC) ck_rw_cohort_rp_##N##_write_unlock(RW, C, GC, LC)
|
|
|
|
|
#define CK_RW_COHORT_RP_DEFAULT_WAIT_LIMIT 1000
|
|
|
|
|
#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_DEFAULT_WAIT_LIMIT 1000
|
|
|
|
|
|
|
|
|
|
#define CK_RW_COHORT_RP_PROTOTYPE(N) \
|
|
|
|
|
CK_RW_COHORT_RP_INSTANCE(N) { \
|
|
|
|
|
#define CK_RWCOHORT_RP_PROTOTYPE(N) \
|
|
|
|
|
CK_RWCOHORT_RP_INSTANCE(N) { \
|
|
|
|
|
unsigned int read_counter; \
|
|
|
|
|
unsigned int read_barrier; \
|
|
|
|
|
unsigned int wait_limit; \
|
|
|
|
|
}; \
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_rp_##N##_init(CK_RW_COHORT_RP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
ck_rwcohort_rp_##N##_init(CK_RWCOHORT_RP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
unsigned int wait_limit) \
|
|
|
|
|
{ \
|
|
|
|
|
rw_cohort->read_counter = 0; \
|
|
|
|
@ -165,7 +165,7 @@
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_rp_##N##_write_lock(CK_RW_COHORT_RP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
ck_rwcohort_rp_##N##_write_lock(CK_RWCOHORT_RP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
|
|
|
|
|
void *local_context) \
|
|
|
|
|
{ \
|
|
|
|
@ -196,7 +196,7 @@
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_rp_##N##_write_unlock(CK_RW_COHORT_RP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
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; \
|
|
|
|
@ -204,7 +204,7 @@
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_rp_##N##_read_lock(CK_RW_COHORT_RP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
ck_rwcohort_rp_##N##_read_lock(CK_RWCOHORT_RP_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
|
|
|
|
|
void *local_context) \
|
|
|
|
|
{ \
|
|
|
|
@ -222,34 +222,34 @@
|
|
|
|
|
\
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_rp_##N##_read_unlock(CK_RW_COHORT_RP_INSTANCE(N) *cohort) \
|
|
|
|
|
ck_rwcohort_rp_##N##_read_unlock(CK_RWCOHORT_RP_INSTANCE(N) *cohort) \
|
|
|
|
|
{ \
|
|
|
|
|
ck_pr_dec_uint(&cohort->read_counter); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define CK_RW_COHORT_RP_INITIALIZER { \
|
|
|
|
|
#define CK_RWCOHORT_RP_INITIALIZER { \
|
|
|
|
|
.read_counter = 0, \
|
|
|
|
|
.read_barrier = 0, \
|
|
|
|
|
.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) ck_rw_cohort_neutral_##N##_init(RW)
|
|
|
|
|
#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_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_DEFAULT_WAIT_LIMIT 1000
|
|
|
|
|
|
|
|
|
|
#define CK_RW_COHORT_NEUTRAL_PROTOTYPE(N) \
|
|
|
|
|
CK_RW_COHORT_NEUTRAL_INSTANCE(N) { \
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_PROTOTYPE(N) \
|
|
|
|
|
CK_RWCOHORT_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) \
|
|
|
|
|
ck_rwcohort_neutral_##N##_init(CK_RWCOHORT_NEUTRAL_INSTANCE(N) *rw_cohort) \
|
|
|
|
|
{ \
|
|
|
|
|
rw_cohort->read_counter = 0; \
|
|
|
|
|
ck_pr_barrier(); \
|
|
|
|
@ -257,7 +257,7 @@
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_neutral_##N##_write_lock(CK_RW_COHORT_NEUTRAL_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
ck_rwcohort_neutral_##N##_write_lock(CK_RWCOHORT_NEUTRAL_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
|
|
|
|
|
void *local_context) \
|
|
|
|
|
{ \
|
|
|
|
@ -269,7 +269,7 @@
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_neutral_##N##_write_unlock(CK_RW_COHORT_NEUTRAL_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
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; \
|
|
|
|
@ -277,7 +277,7 @@
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_neutral_##N##_read_lock(CK_RW_COHORT_NEUTRAL_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
ck_rwcohort_neutral_##N##_read_lock(CK_RWCOHORT_NEUTRAL_INSTANCE(N) *rw_cohort, \
|
|
|
|
|
CK_COHORT_INSTANCE(N) *cohort, void *global_context, \
|
|
|
|
|
void *local_context) \
|
|
|
|
|
{ \
|
|
|
|
@ -290,14 +290,14 @@
|
|
|
|
|
\
|
|
|
|
|
\
|
|
|
|
|
CK_CC_INLINE static void \
|
|
|
|
|
ck_rw_cohort_neutral_##N##_read_unlock(CK_RW_COHORT_NEUTRAL_INSTANCE(N) *cohort) \
|
|
|
|
|
ck_rwcohort_neutral_##N##_read_unlock(CK_RWCOHORT_NEUTRAL_INSTANCE(N) *cohort) \
|
|
|
|
|
{ \
|
|
|
|
|
ck_pr_dec_uint(&cohort->read_counter); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define CK_RW_COHORT_NEUTRAL_INITIALIZER { \
|
|
|
|
|
#define CK_RWCOHORT_NEUTRAL_INITIALIZER { \
|
|
|
|
|
.read_counter = 0, \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _CK_RW_COHORT_H */
|
|
|
|
|
#endif /* _CK_RWCOHORT_H */
|