Refine Naming
This commit is contained in:
1 parent
0159cf30ae
commit
d237a18aae
1 file changed
+3
-3
@@ -13,7 +13,7 @@ class MutexTracker(mutex: Mutex = Mutex(), private var count: Int = 0) : Mutex b
|
||||
get() = count == 0
|
||||
}
|
||||
|
||||
val mutexPool = object : DefaultPool<MutexTracker>(capacity = 32) {
|
||||
object MutexPool : DefaultPool<MutexTracker>(capacity = 32) {
|
||||
override fun produceInstance() = MutexTracker()
|
||||
override fun validateInstance(mutex: MutexTracker) {
|
||||
check(!mutex.isLocked)
|
||||
@@ -25,7 +25,7 @@ val mutexPool = object : DefaultPool<MutexTracker>(capacity = 32) {
|
||||
value class NamedMutex<K>(val active: MutableScatterMap<K, MutexTracker> = mutableScatterMapOf())
|
||||
|
||||
suspend inline fun <K, R> NamedMutex<K>.withLock(key: K, owner: Any? = null, action: () -> R): R {
|
||||
val mutex = synchronized(active) { active.getOrPut(key) { mutexPool.borrow() }.inc() }
|
||||
val mutex = synchronized(active) { active.getOrPut(key) { MutexPool.borrow() }.inc() }
|
||||
return try {
|
||||
mutex.withLock(owner, action)
|
||||
} finally {
|
||||
@@ -33,7 +33,7 @@ suspend inline fun <K, R> NamedMutex<K>.withLock(key: K, owner: Any? = null, act
|
||||
mutex.dec()
|
||||
if (mutex.isFree) {
|
||||
active.remove(key)
|
||||
mutexPool.recycle(mutex)
|
||||
MutexPool.recycle(mutex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user