1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-11 07:17:58 +00:00

Implement cg_lock write biased rwlocks.

This commit is contained in:
ckolivas 2013-03-11 13:23:51 +11:00
parent 590a13dcac
commit 18fc2df483

38
miner.h
View File

@ -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;