Commit 13e36adb authored by Witold Krecicki's avatar Witold Krecicki

Proper implementation of adaptive rwlocks

parent 3535c561
Pipeline #41100 failed with stages
in 63 minutes and 49 seconds
......@@ -397,8 +397,10 @@ isc__rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
isc_result_t
isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
int32_t cnt = 0;
int32_t spins = atomic_load_acquire(&rwl->spins) * 2 + 10;
int32_t max_cnt = ISC_MAX(spins, RWLOCK_MAX_ADAPTIVE_COUNT);
int32_t cachedspins = atomic_load_acquire(&rwl->spins);
int32_t spins = cachedspins * 2 + 10;
int32_t max_cnt = ISC_MIN(spins, RWLOCK_MAX_ADAPTIVE_COUNT);
isc_result_t result = ISC_R_SUCCESS;
do {
......@@ -408,8 +410,12 @@ isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
}
isc_rwlock_pause();
} while (isc_rwlock_trylock(rwl, type) != ISC_R_SUCCESS);
atomic_fetch_add_release(&rwl->spins, (cnt - spins) / 8);
/*
* C99 integer division rounds towards 0, but we want a real 'floor'
* here - otherwise we will never drop to anything below 7.
*/
int32_t update = ((cnt - cachedspins + 9) / 8) - 1;
atomic_fetch_add_release(&rwl->spins, update);
return (result);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment