ISC_MSG_READ, "read") :
isc_msgcat_get(isc_msgcat, ISC_MSGSET_RWLOCK,
ISC_MSG_WRITE, "write")),
- rwl->write_requests, rwl->write_completions,
- rwl->cnt_and_flag, rwl->readers_waiting,
+ atomic_load_explicit(&rwl->write_requests, memory_order_relaxed),
+ atomic_load_explicit(&rwl->write_completions, memory_order_relaxed),
+ atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed),
+ rwl->readers_waiting,
rwl->write_granted, rwl->write_quota);
}
#endif /* ISC_RWLOCK_TRACE */
rwl->magic = 0;
rwl->spins = 0;
- rwl->write_requests = 0;
- rwl->write_completions = 0;
- rwl->cnt_and_flag = 0;
+ atomic_init(&rwl->write_requests, 0);
+ atomic_init(&rwl->write_completions, 0);
+ atomic_init(&rwl->cnt_and_flag, 0);
rwl->readers_waiting = 0;
rwl->write_granted = 0;
if (read_quota != 0) {
isc_rwlock_destroy(isc_rwlock_t *rwl) {
REQUIRE(VALID_RWLOCK(rwl));
- REQUIRE(rwl->write_requests == rwl->write_completions &&
- rwl->cnt_and_flag == 0 && rwl->readers_waiting == 0);
+ REQUIRE(atomic_load_explicit(&rwl->write_requests, memory_order_relaxed) ==
+ atomic_load_explicit(&rwl->write_completions, memory_order_relaxed) &&
+ atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed) == 0 && rwl->readers_waiting == 0);
rwl->magic = 0;
(void)isc_condition_destroy(&rwl->readable);
#endif
if (type == isc_rwlocktype_read) {
- if (rwl->write_requests != rwl->write_completions) {
+ if (atomic_load_explicit(&rwl->write_requests, memory_order_relaxed) !=
+ atomic_load_explicit(&rwl->write_completions, memory_order_relaxed))
+ {
/* there is a waiting or active writer */
LOCK(&rwl->lock);
- if (rwl->write_requests != rwl->write_completions) {
+ if (atomic_load_explicit(&rwl->write_requests, memory_order_relaxed) !=
+ atomic_load_explicit(&rwl->write_completions, memory_order_relaxed)) {
rwl->readers_waiting++;
WAIT(&rwl->readable, &rwl->lock);
rwl->readers_waiting--;
memory_order_relaxed);
POST(cntflag);
while (1) {
- if ((rwl->cnt_and_flag & WRITER_ACTIVE) == 0)
+ if ((atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed) & WRITER_ACTIVE) == 0)
break;
/* A writer is still working */
LOCK(&rwl->lock);
rwl->readers_waiting++;
- if ((rwl->cnt_and_flag & WRITER_ACTIVE) != 0)
+ if ((atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed) & WRITER_ACTIVE) != 0) {
WAIT(&rwl->readable, &rwl->lock);
+ }
rwl->readers_waiting--;
UNLOCK(&rwl->lock);
/* enter the waiting queue, and wait for our turn */
prev_writer = atomic_fetch_add_explicit(&rwl->write_requests, 1,
memory_order_relaxed);
- while (rwl->write_completions != prev_writer) {
+ while (atomic_load_explicit(&rwl->write_completions, memory_order_relaxed) != prev_writer) {
LOCK(&rwl->lock);
- if (rwl->write_completions != prev_writer) {
+ if (atomic_load_explicit(&rwl->write_completions, memory_order_relaxed) != prev_writer) {
WAIT(&rwl->writeable, &rwl->lock);
UNLOCK(&rwl->lock);
continue;
/* Another active reader or writer is working. */
LOCK(&rwl->lock);
- if (rwl->cnt_and_flag != 0)
+ if (atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed) != 0) {
WAIT(&rwl->writeable, &rwl->lock);
+ }
UNLOCK(&rwl->lock);
}
- INSIST((rwl->cnt_and_flag & WRITER_ACTIVE) != 0);
+ INSIST((atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed) & WRITER_ACTIVE));
rwl->write_granted++;
}
if (type == isc_rwlocktype_read) {
/* If a writer is waiting or working, we fail. */
- if (rwl->write_requests != rwl->write_completions)
+ if (atomic_load_explicit(&rwl->write_requests, memory_order_relaxed) !=
+ atomic_load_explicit(&rwl->write_completions, memory_order_relaxed))
return (ISC_R_LOCKBUSY);
/* Otherwise, be ready for reading. */
* new writers in this short period, wake them up.
*/
if (cntflag == READER_INCR &&
- rwl->write_completions != rwl->write_requests) {
+ atomic_load_explicit(&rwl->write_completions, memory_order_relaxed) !=
+ atomic_load_explicit(&rwl->write_requests, memory_order_relaxed)) {
LOCK(&rwl->lock);
BROADCAST(&rwl->writeable);
UNLOCK(&rwl->lock);
* FIFO order.
*/
if (prev_cnt == READER_INCR &&
- rwl->write_completions != rwl->write_requests) {
+ atomic_load_explicit(&rwl->write_completions, memory_order_relaxed) !=
+ atomic_load_explicit(&rwl->write_requests, memory_order_relaxed)) {
LOCK(&rwl->lock);
BROADCAST(&rwl->writeable);
UNLOCK(&rwl->lock);
memory_order_relaxed);
if (rwl->write_granted >= rwl->write_quota ||
- rwl->write_requests == rwl->write_completions ||
- (rwl->cnt_and_flag & ~WRITER_ACTIVE) != 0) {
+ (atomic_load_explicit(&rwl->write_requests, memory_order_relaxed) ==
+ atomic_load_explicit(&rwl->write_completions, memory_order_relaxed)) ||
+ (atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed) & ~WRITER_ACTIVE)) {
/*
* We have passed the write quota, no writer is
* waiting, or some readers are almost ready, pending
UNLOCK(&rwl->lock);
}
- if (rwl->write_requests != rwl->write_completions &&
+ if ((atomic_load_explicit(&rwl->write_requests, memory_order_relaxed) !=
+ atomic_load_explicit(&rwl->write_completions, memory_order_relaxed)) &&
wakeup_writers) {
LOCK(&rwl->lock);
BROADCAST(&rwl->writeable);