ck_rwlock: Re-organization of write-side operations and latch support for write_trylock.

ck_pring
Samy Al Bahra 11 years ago
parent 8173b937bf
commit ab22fda4e7

@ -94,6 +94,21 @@ ck_rwlock_locked(ck_rwlock_t *rw)
return ck_pr_load_32(&rw->n_readers) | r; 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_CC_INLINE static bool
ck_rwlock_write_trylock(ck_rwlock_t *rw) ck_rwlock_write_trylock(ck_rwlock_t *rw)
{ {
@ -103,7 +118,7 @@ ck_rwlock_write_trylock(ck_rwlock_t *rw)
ck_pr_fence_atomic_load(); ck_pr_fence_atomic_load();
if (ck_pr_load_32(&rw->n_readers) != 0) { if (ck_pr_load_32(&rw->n_readers) & CK_RWLOCK_LATCH_READ_MASK) {
ck_rwlock_write_unlock(rw); ck_rwlock_write_unlock(rw);
return false; return false;
} }
@ -144,21 +159,6 @@ ck_rwlock_write_unlatch(ck_rwlock_t *rw)
return; 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_ELIDE_PROTOTYPE(ck_rwlock_write, ck_rwlock_t, CK_ELIDE_PROTOTYPE(ck_rwlock_write, ck_rwlock_t,
ck_rwlock_locked, ck_rwlock_write_lock, ck_rwlock_locked, ck_rwlock_write_lock,
ck_rwlock_locked_writer, ck_rwlock_write_unlock) ck_rwlock_locked_writer, ck_rwlock_write_unlock)

Loading…
Cancel
Save