diff --git a/core/src/main/kotlin/cmu/pasta/fray/core/concurrency/locks/ReferencedContextManager.kt b/core/src/main/kotlin/cmu/pasta/fray/core/concurrency/locks/ReferencedContextManager.kt index 267aeb70..4ccb07ff 100644 --- a/core/src/main/kotlin/cmu/pasta/fray/core/concurrency/locks/ReferencedContextManager.kt +++ b/core/src/main/kotlin/cmu/pasta/fray/core/concurrency/locks/ReferencedContextManager.kt @@ -10,27 +10,26 @@ class IdentityPhantomReference(referent: T, queue: ReferenceQueue) : class ReferencedContextManager(val contextProducer: (Any) -> T) { val queue = ReferenceQueue() - val lockMap = mutableMapOf() + val lockMap = mutableMapOf>>() fun getLockContext(lock: Any): T { val id = System.identityHashCode(lock) if (!lockMap.containsKey(id)) { - lockMap[id] = contextProducer(lock) - IdentityPhantomReference(lock, queue) + lockMap[id] = Pair(contextProducer(lock), IdentityPhantomReference(lock, queue)) gc() } - return lockMap[id]!! + return lockMap[id]!!.first } fun addContext(lock: Any, context: T) { val id = System.identityHashCode(lock) - lockMap[id] = context - IdentityPhantomReference(lock, queue) + lockMap[id] = Pair(context, IdentityPhantomReference(lock, queue)) gc() } fun done() { gc() + lockMap.clear() } fun gc() {