fixing upgrade logic bug
This commit is contained in:
@@ -35,7 +35,9 @@ inline fun <erased T> ReentrantReadWriteLock.read(action: ()->T) : T {
|
||||
}
|
||||
|
||||
/*
|
||||
Executes given calculation under write lock doing upgrade from read lock if needed
|
||||
Executes given calculation under write lock.
|
||||
The method does upgrade from read to write lock if needed
|
||||
If such write has been initiated by checking some condition, the condition must be rechecked inside the action to avoid possible races
|
||||
Returns result of the calculation
|
||||
*/
|
||||
inline fun <erased T> ReentrantReadWriteLock.write(action: ()->T) : T {
|
||||
@@ -46,6 +48,9 @@ inline fun <erased T> ReentrantReadWriteLock.write(action: ()->T) : T {
|
||||
if(upgradeCount > 0)
|
||||
rl.unlock(upgradeCount)
|
||||
}
|
||||
else {
|
||||
upgradeCount = 0
|
||||
}
|
||||
|
||||
val wl = writeLock().sure()
|
||||
wl.lock()
|
||||
|
||||
Reference in New Issue
Block a user