Created
September 12, 2016 12:48
-
-
Save DengYiping/45d5eb97ed142ad872f5cb6f4553d674 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util | |
import java.util.concurrent.locks.ReentrantReadWriteLock | |
/** | |
* Created by Scott on 9/12/16. | |
*/ | |
class ReadWriteLocker { | |
private val rwlock = new ReentrantReadWriteLock() | |
def readSync[T,R](func:T => R): T => R ={ | |
def new_func(para:T):R = { | |
rwlock.readLock().lock() | |
val result = func(para) | |
rwlock.readLock().unlock() | |
result | |
} | |
new_func | |
} | |
def writeSync[T,R](func:T => R): T => R ={ | |
def new_func(para:T):R = { | |
rwlock.writeLock().lock() | |
val result = func(para) | |
rwlock.writeLock().unlock() | |
result | |
} | |
new_func | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment