/* * Read-write spinlocks, allowing multiple readers but only one writer. * Unfair locking as Writers could be starved indefinitely by Reader(s) * * The spinlock itself is contained in @counter and access to it is * serialized with @lock_mutex.
*/
/* 1 - lock taken successfully */ staticinlineint arch_read_trylock(arch_rwlock_t *rw)
{ int ret = 0; unsignedlong flags;
/* * zero means writer holds the lock exclusively, deny Reader. * Otherwise grant lock to first/subseq reader
*/ if (rw->counter > 0) {
rw->counter--;
ret = 1;
}
/* * If reader(s) hold lock (lock < __ARCH_RW_LOCK_UNLOCKED__), * deny writer. Otherwise if unlocked grant to writer * Hence the claim that Linux rwlocks are unfair to writers. * (can be starved for an indefinite time by readers).
*/ if (rw->counter == __ARCH_RW_LOCK_UNLOCKED__) {
rw->counter = 0;
ret = 1;
}
arch_spin_unlock(&(rw->lock_mutex));
local_irq_restore(flags);
return ret;
}
staticinlinevoid arch_read_lock(arch_rwlock_t *rw)
{ while (!arch_read_trylock(rw))
cpu_relax();
}
staticinlinevoid arch_write_lock(arch_rwlock_t *rw)
{ while (!arch_write_trylock(rw))
cpu_relax();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.