From a1daff18ea3e266cf3798f4b7a58f9ca378d94bb Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Fri, 18 Apr 2014 15:33:18 -0400 Subject: [PATCH] ck_swlock: Switch to TATAS style loop for latch operations. --- include/ck_swlock.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/ck_swlock.h b/include/ck_swlock.h index ceafe85..22f4647 100644 --- a/include/ck_swlock.h +++ b/include/ck_swlock.h @@ -124,12 +124,14 @@ ck_swlock_write_latch(ck_swlock_t *rw) { ck_pr_store_32(&rw->writer, 1); - ck_pr_fence_atomic_load(); /* Stall until readers have seen the latch and cleared. */ - while (ck_pr_cas_32(&rw->n_readers, 0, CK_SWLOCK_LATCH_BIT) == false) - ck_pr_stall(); + while (ck_pr_cas_32(&rw->n_readers, 0, CK_SWLOCK_LATCH_BIT) == false) { + do { + ck_pr_stall(); + } while (ck_pr_load_uint(&rw->n_readers) != 0); + } return; } @@ -292,8 +294,11 @@ ck_swlock_recursive_write_latch(ck_swlock_recursive_t *rw) ck_pr_store_32(&rw->rw.writer, 1); ck_pr_fence_store_load(); - while (ck_pr_cas_32(&rw->rw.n_readers, 0, CK_SWLOCK_LATCH_BIT) == false) - ck_pr_stall(); + while (ck_pr_cas_32(&rw->rw.n_readers, 0, CK_SWLOCK_LATCH_BIT) == false) { + do { + ck_pr_stall(); + } while (ck_pr_load_uint(&rw->n_readers) != 0); + } rw->wc++; return;