From d9b7092a874a93b03e37a36718f76f3a1ab8da9f Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Tue, 6 Aug 2019 14:35:06 +0200 Subject: [PATCH] Clang: Use no mutex in copyable file path cache We use it in worker threads and there should be no access from different threads. Change-Id: I62874761221c45f88ce4d7cfda4fbda4bc446cac Reviewed-by: Tim Jenssen --- src/libs/clangsupport/filepathcache.h | 29 ++++++++++++++++++------- src/libs/clangsupport/filepathcaching.h | 4 ++-- src/libs/clangsupport/stringcache.h | 27 ++++++++++++++++++----- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/libs/clangsupport/filepathcache.h b/src/libs/clangsupport/filepathcache.h index 1771f5b6c3a..2faef6e5037 100644 --- a/src/libs/clangsupport/filepathcache.h +++ b/src/libs/clangsupport/filepathcache.h @@ -37,28 +37,31 @@ namespace ClangBackEnd { -template +template class CLANGSUPPORT_GCCEXPORT FilePathCache { + FilePathCache(const FilePathCache &) = default; + FilePathCache &operator=(const FilePathCache &) = default; + + template + friend class FilePathCache; + +public: using DirectoryPathCache = StringCache; using FileNameCache = StringCache; - FilePathCache(const FilePathCache &) = default; - FilePathCache &operator=(const FilePathCache &) = default; - -public: FilePathCache(FilePathStorage &filePathStorage) : m_filePathStorage(filePathStorage) { @@ -69,7 +72,17 @@ public: FilePathCache(FilePathCache &&) = default; FilePathCache &operator=(FilePathCache &&) = default; - FilePathCache clone() { return *this; } + template + Cache clone() + { + using DirectoryPathCache = typename Cache::DirectoryPathCache; + using FileNameCache = typename Cache::FileNameCache; + Cache cache{m_filePathStorage}; + cache.m_directoryPathCache = m_directoryPathCache.template clone(); + cache.m_fileNameCache = m_fileNameCache.template clone(); + + return cache; + } FilePathId filePathId(FilePathView filePath) const { diff --git a/src/libs/clangsupport/filepathcaching.h b/src/libs/clangsupport/filepathcaching.h index 1ca6522752e..8bbbe0e43e0 100644 --- a/src/libs/clangsupport/filepathcaching.h +++ b/src/libs/clangsupport/filepathcaching.h @@ -66,11 +66,11 @@ class CLANGSUPPORT_EXPORT CopyableFilePathCaching final : public FilePathCaching { using Factory = FilePathStorageSqliteStatementFactory; using Storage = FilePathStorage; - using Cache = FilePathCache; + using Cache = FilePathCache; public: CopyableFilePathCaching(FilePathCaching &cache) - : m_cache(cache.m_cache.clone()) + : m_cache(cache.m_cache.clone()) {} FilePathId filePathId(FilePathView filePath) const override; diff --git a/src/libs/clangsupport/stringcache.h b/src/libs/clangsupport/stringcache.h index 5d416a46c40..5a1ea8fd354 100644 --- a/src/libs/clangsupport/stringcache.h +++ b/src/libs/clangsupport/stringcache.h @@ -101,6 +101,9 @@ template> class StringCache { + template + friend class StringCache; + public: using CacheEntries = std::vector; using const_iterator = typename CacheEntries::const_iterator; @@ -116,12 +119,26 @@ public: : m_strings(other.m_strings) , m_indices(other.m_indices) {} - StringCache &operator=(const StringCache &other) + + template + Cache clone() { - if (*this != other) { - m_strings = other.m_strings; - m_indices = other.m_indices; - } + Cache cache; + cache.m_strings = m_strings; + cache.m_indices = m_indices; + + return cache; + } + + StringCache(StringCache &&other) + : m_strings(std::move(other.m_strings)) + , m_indices(std::move(other.m_indices)) + {} + + StringCache &operator=(StringCache &&other) + { + m_strings = std::move(other.m_strings); + m_indices = std::move(other.m_indices); return *this; }