diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2017-02-09 21:38:48 -0500 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2017-02-09 22:58:10 -0500 |
commit | f42d50ab33a829322618181375cb6c5f2e71118a (patch) | |
tree | 5013e17d4517256a9586e58f73f763996559565a /stage1/KeyLockedLazyCache.scala | |
parent | 75092dd02fb76a6607f2aaa8f0dc04b2a88699b4 (diff) | |
download | cbt-f42d50ab33a829322618181375cb6c5f2e71118a.tar.gz cbt-f42d50ab33a829322618181375cb6c5f2e71118a.tar.bz2 cbt-f42d50ab33a829322618181375cb6c5f2e71118a.zip |
various smaller changes
Diffstat (limited to 'stage1/KeyLockedLazyCache.scala')
-rw-r--r-- | stage1/KeyLockedLazyCache.scala | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/stage1/KeyLockedLazyCache.scala b/stage1/KeyLockedLazyCache.scala index 2047b81..aac32a3 100644 --- a/stage1/KeyLockedLazyCache.scala +++ b/stage1/KeyLockedLazyCache.scala @@ -10,7 +10,11 @@ final private[cbt] class KeyLockedLazyCache[T <: AnyRef]( val hashMap: java.util.Map[AnyRef,AnyRef], logger: Option[Logger] ){ + final val seen = new ThreadLocal[collection.mutable.Set[AnyRef]](){ + override protected def initialValue = collection.mutable.Set[AnyRef](); + } def get( key: AnyRef, value: => T ): T = { + seen.get.add( key ); val lockableKey = hashMap.synchronized{ if( ! (hashMap containsKey key) ){ val lockableKey = new LockableKey @@ -35,6 +39,10 @@ final private[cbt] class KeyLockedLazyCache[T <: AnyRef]( } } def update( key: AnyRef, value: T ): T = { + assert( + !seen.get.contains( key ), + "Thread tries to update cache key after observing it: " + key + ) val lockableKey = hashMap get key lockableKey.synchronized{ hashMap.put( lockableKey, value ) |