com.wavesenterprise.utils.ReadWriteLocking.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of we-utils Show documentation
Show all versions of we-utils Show documentation
Library for Waves Enterprise blockchain platform
package com.wavesenterprise.utils
import java.util.concurrent.locks.{Lock, ReadWriteLock}
/**
* A common wrapper for ReadWrite lock
*/
trait ReadWriteLocking {
protected val lock: ReadWriteLock
private def inLock[R](l: Lock, f: => R): R = {
try {
l.lock()
f
} finally {
l.unlock()
}
}
protected def writeLock[B](f: => B): B = inLock(lock.writeLock(), f)
protected def readLock[B](f: => B): B = inLock(lock.readLock(), f)
}