All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wavesenterprise.utils.ReadWriteLocking.scala Maven / Gradle / Ivy

There is a newer version: 1.16.0
Show newest version
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)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy