review: Final ck_cohort review changes

I changed the release state to use an enum instead of an unsigned int with #defines in order to make debugging easier.  I also removed unnecessary atomic operations in the initializer function, and made some formatting fixes.
ck_pring
Brendon Scheinman 13 years ago
parent 81a90e41a2
commit caef3b4ac2

@ -28,7 +28,8 @@
#ifndef _CK_COHORT_H #ifndef _CK_COHORT_H
#define _CK_COHORT_H #define _CK_COHORT_H
/* This is an implementation of lock cohorts as described in: /*
* This is an implementation of lock cohorts as described in:
* Dice, D.; Marathe, V.; and Shavit, N. 2012. * Dice, D.; Marathe, V.; and Shavit, N. 2012.
* Lock Cohorting: A General Technique for Designing NUMA Locks * Lock Cohorting: A General Technique for Designing NUMA Locks
*/ */
@ -37,10 +38,12 @@
#include <ck_pr.h> #include <ck_pr.h>
#include <stddef.h> #include <stddef.h>
#define CK_COHORT_RELEASE_STATE_GLOBAL 0 enum ck_cohort_state {
#define CK_COHORT_RELEASE_STATE_LOCAL 1 CK_COHORT_STATE_GLOBAL = 0,
CK_COHORT_STATE_LOCAL = 1
};
#define CK_COHORT_DEFAULT_LOCAL_PASS_LIMIT 10 #define CK_COHORT_DEFAULT_LOCAL_PASS_LIMIT 10
#define CK_COHORT_NAME(N) ck_cohort_##N #define CK_COHORT_NAME(N) ck_cohort_##N
#define CK_COHORT_INSTANCE(N) struct CK_COHORT_NAME(N) #define CK_COHORT_INSTANCE(N) struct CK_COHORT_NAME(N)
@ -53,7 +56,7 @@
CK_COHORT_INSTANCE(N) { \ CK_COHORT_INSTANCE(N) { \
GT *global_lock; \ GT *global_lock; \
LT *local_lock; \ LT *local_lock; \
unsigned int release_state; \ enum ck_cohort_state release_state; \
unsigned int waiting_threads; \ unsigned int waiting_threads; \
unsigned int acquire_count; \ unsigned int acquire_count; \
unsigned int local_pass_limit; \ unsigned int local_pass_limit; \
@ -63,13 +66,13 @@
ck_cohort_##N##_init(struct ck_cohort_##N *cohort, \ ck_cohort_##N##_init(struct ck_cohort_##N *cohort, \
GT *global_lock, LT *local_lock, unsigned int pass_limit) \ GT *global_lock, LT *local_lock, unsigned int pass_limit) \
{ \ { \
ck_pr_store_ptr(&cohort->global_lock, global_lock); \ cohort->global_lock = global_lock; \
ck_pr_store_ptr(&cohort->local_lock, local_lock); \ cohort->local_lock = local_lock; \
ck_pr_store_uint(&cohort->release_state, \ cohort->release_state = CK_COHORT_STATE_GLOBAL; \
CK_COHORT_RELEASE_STATE_GLOBAL); \ cohort->waiting_threads = 0; \
ck_pr_store_uint(&cohort->waiting_threads, 0); \ cohort->acquire_count = 0; \
ck_pr_store_uint(&cohort->acquire_count, 0); \ cohort->local_pass_limit = pass_limit; \
ck_pr_store_uint(&cohort->local_pass_limit, pass_limit); \ ck_pr_barrier(); \
return; \ return; \
} \ } \
\ \
@ -81,13 +84,11 @@
LL(cohort->local_lock, local_context); \ LL(cohort->local_lock, local_context); \
ck_pr_dec_uint(&cohort->waiting_threads); \ ck_pr_dec_uint(&cohort->waiting_threads); \
\ \
if (cohort->release_state == CK_COHORT_RELEASE_STATE_GLOBAL) { \ if (cohort->release_state == CK_COHORT_STATE_GLOBAL) { \
GL(cohort->global_lock, global_context); \ GL(cohort->global_lock, global_context); \
cohort->release_state = CK_COHORT_RELEASE_STATE_LOCAL; \
} \ } \
\ \
++cohort->acquire_count; \ ++cohort->acquire_count; \
ck_pr_fence_memory(); \
return; \ return; \
} \ } \
\ \
@ -97,10 +98,10 @@
{ \ { \
if (ck_pr_load_uint(&cohort->waiting_threads) > 0 \ if (ck_pr_load_uint(&cohort->waiting_threads) > 0 \
&& cohort->acquire_count < cohort->local_pass_limit) { \ && cohort->acquire_count < cohort->local_pass_limit) { \
cohort->release_state = CK_COHORT_RELEASE_STATE_LOCAL; \ cohort->release_state = CK_COHORT_STATE_LOCAL; \
} else { \ } else { \
GU(cohort->global_lock, global_context); \ GU(cohort->global_lock, global_context); \
cohort->release_state = CK_COHORT_RELEASE_STATE_GLOBAL; \ cohort->release_state = CK_COHORT_STATE_GLOBAL; \
cohort->acquire_count = 0; \ cohort->acquire_count = 0; \
} \ } \
\ \
@ -111,11 +112,14 @@
} }
#define CK_COHORT_INITIALIZER \ #define CK_COHORT_INITIALIZER { \
{ .global_lock = NULL, .local_lock = NULL, \ .global_lock = NULL, \
.release_state = CK_COHORT_RELEASE_STATE_GLOBAL, \ .local_lock = NULL, \
.waiting_threads = 0, .acquire_count = 0, \ .release_state = CK_COHORT_STATE_GLOBAL, \
.local_pass_limit = CK_COHORT_DEFAULT_LOCAL_PASS_LIMIT } .waiting_threads = 0, \
.acquire_count = 0, \
.local_pass_limit = CK_COHORT_DEFAULT_LOCAL_PASS_LIMIT \
}
#endif /* _CK_COHORT_H */ #endif /* _CK_COHORT_H */
Loading…
Cancel
Save