From bc7ebc62eb69f3418cf51573fb13dea85369f5a3 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Thu, 17 Apr 2014 14:41:12 -0400 Subject: [PATCH] ck_rwlock: Add ck_rwlock_read_latchlock operation. This avoids degradation on read_lock path for use-cases not requiring latch semantics. --- include/ck_rwlock.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/ck_rwlock.h b/include/ck_rwlock.h index 66b12f2..c92ab5c 100644 --- a/include/ck_rwlock.h +++ b/include/ck_rwlock.h @@ -190,6 +190,33 @@ CK_ELIDE_TRYLOCK_PROTOTYPE(ck_rwlock_read, ck_rwlock_t, CK_CC_INLINE static void ck_rwlock_read_lock(ck_rwlock_t *rw) +{ + + for (;;) { + while (ck_pr_load_32(&rw->writer) != 0) + ck_pr_stall(); + + ck_pr_inc_32(&rw->n_readers); + + /* + * Serialize with respect to concurrent write + * lock operation. + */ + ck_pr_fence_atomic_load(); + + if (ck_pr_load_32(&rw->writer) == 0) + break; + + ck_pr_dec_32(&rw->n_readers); + } + + /* Acquire semantics are necessary. */ + ck_pr_fence_load(); + return; +} + +CK_CC_INLINE static void +ck_rwlock_read_latchlock(ck_rwlock_t *rw) { uint32_t snapshot;