From 8c53de1e70e1dfbd7b9db489a635c0f26f1bdca5 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Sat, 9 Feb 2013 15:50:25 -0500 Subject: [PATCH] ck_rwlock: Add documentation on visibility semantics. --- include/ck_rwlock.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/ck_rwlock.h b/include/ck_rwlock.h index 01a8389..45593b0 100644 --- a/include/ck_rwlock.h +++ b/include/ck_rwlock.h @@ -106,6 +106,11 @@ ck_rwlock_read_trylock(ck_rwlock_t *rw) return false; ck_pr_inc_uint(&rw->n_readers); + + /* + * Serialize with respect to concurrent write + * lock operation. + */ ck_pr_fence_memory(); if (ck_pr_load_uint(&rw->writer) == 0) goto leave; @@ -113,6 +118,7 @@ ck_rwlock_read_trylock(ck_rwlock_t *rw) return false; leave: + /* Acquire semantics are necessary. */ ck_pr_fence_load(); return true; } @@ -126,12 +132,18 @@ ck_rwlock_read_lock(ck_rwlock_t *rw) ck_pr_stall(); ck_pr_inc_uint(&rw->n_readers); + + /* + * Serialize with respect to concurrent write + * lock operation. + */ ck_pr_fence_memory(); if (ck_pr_load_uint(&rw->writer) == 0) break; ck_pr_dec_uint(&rw->n_readers); } + /* Acquire semantics are necessary. */ ck_pr_fence_load(); return; }