Fixed deadlock when Transactor is restarted in the middle of a transaction

This commit is contained in:
Jonas Bonér 2010-07-14 12:51:00 +02:00
parent b98cfd5c1f
commit 4d130d544d
6 changed files with 82 additions and 63 deletions

View file

@ -10,7 +10,7 @@ import java.util.concurrent.locks.{ReentrantReadWriteLock, ReentrantLock}
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
class ReentrantGuard {
private val lock = new ReentrantLock
val lock = new ReentrantLock
def withGuard[T](body: => T): T = {
lock.lock
@ -20,6 +20,15 @@ class ReentrantGuard {
lock.unlock
}
}
def tryWithGuard[T](body: => T): T = {
while(!lock.tryLock) { Thread.sleep(10) } // wait on the monitor to be unlocked
try {
body
} finally {
lock.unlock
}
}
}
/**