fixing upgrade logic bug

This commit is contained in:
Alex Tkachman
2012-02-01 13:06:11 +02:00
parent e7812dc472
commit 68a264154f
+6 -1
View File
@@ -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()