Implement cg_lock write biased rwlocks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
diff --git a/miner.h b/miner.h
index bd24305..fadbf09 100644
--- a/miner.h
+++ b/miner.h
@@ -696,6 +696,44 @@ static inline void rwlock_init(pthread_rwlock_t *lock)
quit(1, "Failed to pthread_rwlock_init");
}
+/* cgminer locks, a write biased variant of rwlocks */
+struct cglock {
+ pthread_mutex_t mutex;
+ pthread_rwlock_t rwlock;
+};
+
+typedef struct cglock cglock_t;
+
+static inline void cglock_init(cglock_t *lock)
+{
+ mutex_init(&lock->mutex);
+ rwlock_init(&lock->rwlock);
+}
+
+static inline void cg_rlock(cglock_t *lock)
+{
+ mutex_lock(&lock->mutex);
+ rd_lock(&lock->rwlock);
+ mutex_unlock(&lock->mutex);
+}
+
+static inline void cg_wlock(cglock_t *lock)
+{
+ mutex_lock(&lock->mutex);
+ wr_lock(&lock->rwlock);
+ mutex_unlock(&lock->mutex);
+}
+
+static inline void cg_runlock(cglock_t *lock)
+{
+ rd_unlock(&lock->rwlock);
+}
+
+static inline void cg_wunlock(cglock_t *lock)
+{
+ wr_unlock(&lock->rwlock);
+}
+
struct pool;
extern bool opt_protocol;