From 91b86d7fba2857d0009ffbb1a7db93425e726bce Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Thu, 31 May 2018 13:05:40 +0300 Subject: [PATCH] Remove explicit locks for accessing and creating cached values Working with user data in cached value manager is already thread safe. --- .../caches/resolve/KotlinCacheServiceImpl.kt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt index 57ca2a1db1e..6dfa1a6a26f 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt @@ -357,14 +357,14 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService { } private fun getFacadeForSpecialFiles(files: Set): ProjectResolutionFacade { - val cachedValue: SLRUCache, ProjectResolutionFacade> = synchronized(specialFilesCacheProvider) { + val cachedValue: SLRUCache, ProjectResolutionFacade> = CachedValuesManager.getManager(project).getCachedValue(project, specialFilesCacheProvider) - } + // In Upsource, we create multiple instances of KotlinCacheService, which all access the same CachedValue instance (UP-8046) // This is so because class name of provider is used as a key when fetching cached value, see CachedValueManager.getKeyForClass. - // To avoid race conditions, we can't use the local lock to access the cached value contents. - synchronized(cachedValue) { - return cachedValue.get(files) + // To avoid race conditions, we can't use any local lock to access the cached value contents. + return synchronized(cachedValue) { + cachedValue.get(files) } } @@ -380,12 +380,11 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService { } private fun getFacadeForScripts(files: Set): ProjectResolutionFacade { - val cachedValue: SLRUCache, ProjectResolutionFacade> = synchronized(scriptsCacheProvider) { + val cachedValue: SLRUCache, ProjectResolutionFacade> = CachedValuesManager.getManager(project).getCachedValue(project, scriptsCacheProvider) - } - synchronized(cachedValue) { - return cachedValue.get(files) + return synchronized(cachedValue) { + cachedValue.get(files) } }