From 5683a1144eb2f647800e2b505aaabd4e6edfa155 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 29 Sep 2013 15:14:06 +1000 Subject: [PATCH] Provide a function to downgrade a cglock from a write lock to an intermediate variant. --- miner.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/miner.h b/miner.h index d945740e..60eb7516 100644 --- a/miner.h +++ b/miner.h @@ -843,7 +843,7 @@ static inline void cglock_init(cglock_t *lock) rwlock_init(&lock->rwlock); } -/* Read lock variant of cglock */ +/* Read lock variant of cglock. Cannot be promoted. */ static inline void cg_rlock(cglock_t *lock) { mutex_lock(&lock->mutex); @@ -851,7 +851,8 @@ static inline void cg_rlock(cglock_t *lock) mutex_unlock_noyield(&lock->mutex); } -/* Intermediate variant of cglock */ +/* Intermediate variant of cglock - behaves as a read lock but can be promoted + * to a write lock or demoted to read lock. */ static inline void cg_ilock(cglock_t *lock) { mutex_lock(&lock->mutex); @@ -878,6 +879,12 @@ static inline void cg_dwlock(cglock_t *lock) mutex_unlock_noyield(&lock->mutex); } +/* Demote a write variant to an intermediate variant */ +static inline void cg_dwilock(cglock_t *lock) +{ + wr_unlock(&lock->rwlock); +} + /* Downgrade intermediate variant to a read lock */ static inline void cg_dlock(cglock_t *lock) {