|
|
|
@ -46,7 +46,7 @@ ck_rwlock_init(struct ck_rwlock *rw)
|
|
|
|
|
|
|
|
|
|
rw->writer = 0;
|
|
|
|
|
rw->n_readers = 0;
|
|
|
|
|
ck_pr_fence_memory();
|
|
|
|
|
ck_pr_fence_store();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -54,7 +54,7 @@ CK_CC_INLINE static void
|
|
|
|
|
ck_rwlock_write_unlock(ck_rwlock_t *rw)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ck_pr_fence_memory();
|
|
|
|
|
ck_pr_fence_release();
|
|
|
|
|
ck_pr_store_uint(&rw->writer, 0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -95,7 +95,7 @@ ck_rwlock_write_trylock(ck_rwlock_t *rw)
|
|
|
|
|
if (ck_pr_fas_uint(&rw->writer, 1) != 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
ck_pr_fence_memory();
|
|
|
|
|
ck_pr_fence_atomic_load();
|
|
|
|
|
|
|
|
|
|
if (ck_pr_load_uint(&rw->n_readers) != 0) {
|
|
|
|
|
ck_rwlock_write_unlock(rw);
|
|
|
|
@ -115,7 +115,7 @@ ck_rwlock_write_lock(ck_rwlock_t *rw)
|
|
|
|
|
while (ck_pr_fas_uint(&rw->writer, 1) != 0)
|
|
|
|
|
ck_pr_stall();
|
|
|
|
|
|
|
|
|
|
ck_pr_fence_memory();
|
|
|
|
|
ck_pr_fence_atomic_load();
|
|
|
|
|
|
|
|
|
|
while (ck_pr_load_uint(&rw->n_readers) != 0)
|
|
|
|
|
ck_pr_stall();
|
|
|
|
@ -140,7 +140,7 @@ ck_rwlock_read_trylock(ck_rwlock_t *rw)
|
|
|
|
|
* Serialize with respect to concurrent write
|
|
|
|
|
* lock operation.
|
|
|
|
|
*/
|
|
|
|
|
ck_pr_fence_memory();
|
|
|
|
|
ck_pr_fence_atomic_load();
|
|
|
|
|
|
|
|
|
|
if (ck_pr_load_uint(&rw->writer) == 0) {
|
|
|
|
|
ck_pr_fence_load();
|
|
|
|
@ -193,7 +193,7 @@ CK_CC_INLINE static void
|
|
|
|
|
ck_rwlock_read_unlock(ck_rwlock_t *rw)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ck_pr_fence_memory();
|
|
|
|
|
ck_pr_fence_load_atomic();
|
|
|
|
|
ck_pr_dec_uint(&rw->n_readers);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -225,7 +225,7 @@ ck_rwlock_recursive_write_lock(ck_rwlock_recursive_t *rw, unsigned int tid)
|
|
|
|
|
while (ck_pr_cas_uint(&rw->rw.writer, 0, tid) == false)
|
|
|
|
|
ck_pr_stall();
|
|
|
|
|
|
|
|
|
|
ck_pr_fence_memory();
|
|
|
|
|
ck_pr_fence_atomic_load();
|
|
|
|
|
|
|
|
|
|
while (ck_pr_load_uint(&rw->rw.n_readers) != 0)
|
|
|
|
|
ck_pr_stall();
|
|
|
|
@ -247,7 +247,7 @@ ck_rwlock_recursive_write_trylock(ck_rwlock_recursive_t *rw, unsigned int tid)
|
|
|
|
|
if (ck_pr_cas_uint(&rw->rw.writer, 0, tid) == false)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
ck_pr_fence_memory();
|
|
|
|
|
ck_pr_fence_atomic_load();
|
|
|
|
|
|
|
|
|
|
if (ck_pr_load_uint(&rw->rw.n_readers) != 0) {
|
|
|
|
|
ck_pr_store_uint(&rw->rw.writer, 0);
|
|
|
|
@ -264,7 +264,7 @@ ck_rwlock_recursive_write_unlock(ck_rwlock_recursive_t *rw)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (--rw->wc == 0) {
|
|
|
|
|
ck_pr_fence_memory();
|
|
|
|
|
ck_pr_fence_release();
|
|
|
|
|
ck_pr_store_uint(&rw->rw.writer, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|