From 9aad0125af9d8adc3ab6f94f3dd338e36ba4f0c6 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Thu, 17 Apr 2014 16:16:42 -0400 Subject: [PATCH] Revert "ck_rwlock: Additional re-organization of write-side functions." This reverts commit d9b86d2d89883a07317980eb37b2216b62291d52. --- include/ck_rwlock.h | 64 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/include/ck_rwlock.h b/include/ck_rwlock.h index 03440e8..5d6fc7b 100644 --- a/include/ck_rwlock.h +++ b/include/ck_rwlock.h @@ -56,38 +56,6 @@ ck_rwlock_init(struct ck_rwlock *rw) return; } -CK_CC_INLINE static void -ck_rwlock_write_lock(ck_rwlock_t *rw) -{ - - while (ck_pr_fas_32(&rw->writer, 1) != 0) - ck_pr_stall(); - - ck_pr_fence_atomic_load(); - - while (ck_pr_load_32(&rw->n_readers) & CK_RWLOCK_LATCH_READ_MASK) - ck_pr_stall(); - - return; -} - -CK_CC_INLINE static bool -ck_rwlock_write_trylock(ck_rwlock_t *rw) -{ - - if (ck_pr_fas_32(&rw->writer, 1) != 0) - return false; - - ck_pr_fence_atomic_load(); - - if (ck_pr_load_32(&rw->n_readers) & CK_RWLOCK_LATCH_READ_MASK) { - ck_rwlock_write_unlock(rw); - return false; - } - - return true; -} - CK_CC_INLINE static void ck_rwlock_write_unlock(ck_rwlock_t *rw) { @@ -126,6 +94,38 @@ ck_rwlock_locked(ck_rwlock_t *rw) return ck_pr_load_32(&rw->n_readers) | r; } +CK_CC_INLINE static void +ck_rwlock_write_lock(ck_rwlock_t *rw) +{ + + while (ck_pr_fas_32(&rw->writer, 1) != 0) + ck_pr_stall(); + + ck_pr_fence_atomic_load(); + + while (ck_pr_load_32(&rw->n_readers) & CK_RWLOCK_LATCH_READ_MASK) + ck_pr_stall(); + + return; +} + +CK_CC_INLINE static bool +ck_rwlock_write_trylock(ck_rwlock_t *rw) +{ + + if (ck_pr_fas_32(&rw->writer, 1) != 0) + return false; + + ck_pr_fence_atomic_load(); + + if (ck_pr_load_32(&rw->n_readers) & CK_RWLOCK_LATCH_READ_MASK) { + ck_rwlock_write_unlock(rw); + return false; + } + + return true; +} + CK_ELIDE_TRYLOCK_PROTOTYPE(ck_rwlock_write, ck_rwlock_t, ck_rwlock_locked, ck_rwlock_write_trylock)