From 80a9b6ff9c1b242ecd615fd81cf2ecf63dd03d27 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Mon, 28 Dec 2015 04:05:32 -0500 Subject: [PATCH] epoch: Fix fat-finger that breaks epoch sections. And this is why tests should also be validated against fault injection. --- include/ck_epoch.h | 2 +- src/ck_epoch.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/ck_epoch.h b/include/ck_epoch.h index 1cffa29..b492288 100644 --- a/include/ck_epoch.h +++ b/include/ck_epoch.h @@ -47,7 +47,7 @@ * This is used for sense detection with-respect to concurrent * epoch sections. */ -#define CK_EPOCH_SENSE 2 +#define CK_EPOCH_SENSE (2) struct ck_epoch_entry; typedef struct ck_epoch_entry ck_epoch_entry_t; diff --git a/src/ck_epoch.c b/src/ck_epoch.c index b04a302..f45dd2e 100644 --- a/src/ck_epoch.c +++ b/src/ck_epoch.c @@ -137,6 +137,8 @@ CK_STACK_CONTAINER(struct ck_epoch_record, record_next, CK_STACK_CONTAINER(struct ck_epoch_entry, stack_entry, ck_epoch_entry_container) +#define CK_EPOCH_SENSE_MASK (CK_EPOCH_SENSE - 1) + void _ck_epoch_delref(struct ck_epoch_record *record, struct ck_epoch_section *section) @@ -159,7 +161,8 @@ _ck_epoch_delref(struct ck_epoch_record *record, if (current->count == 0) { struct ck_epoch_ref *other; - other = &record->local.bucket[(i + 1) & CK_EPOCH_SENSE]; + other = &record->local.bucket[(i + 1) & + CK_EPOCH_SENSE_MASK]; if (other->count > 0 && ((int)(current->epoch - other->epoch) < 0 || (current->epoch - other->epoch) > 1)) { @@ -183,7 +186,7 @@ _ck_epoch_addref(struct ck_epoch_record *record, unsigned int epoch, i; epoch = ck_pr_load_uint(&global->epoch); - i = epoch & (CK_EPOCH_SENSE - 1); + i = epoch & CK_EPOCH_SENSE_MASK; ref = &record->local.bucket[i]; if (ref->count++ == 0) { @@ -200,7 +203,8 @@ _ck_epoch_addref(struct ck_epoch_record *record, * and load-{store, load} ordering are sufficient to guarantee * this ordering. */ - previous = &record->local.bucket[(i + 1) & CK_EPOCH_SENSE]; + previous = &record->local.bucket[(i + 1) & + CK_EPOCH_SENSE_MASK]; if (previous->count > 0) ck_pr_fence_acqrel(); #endif /* !CK_MD_TSO */