forked from qt-creator/qt-creator
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 <tim.jenssen@qt.io>
This commit is contained in:
@@ -37,28 +37,31 @@
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
template <typename FilePathStorage>
|
||||
template<typename FilePathStorage, typename Mutex = SharedMutex>
|
||||
class CLANGSUPPORT_GCCEXPORT FilePathCache
|
||||
{
|
||||
FilePathCache(const FilePathCache &) = default;
|
||||
FilePathCache &operator=(const FilePathCache &) = default;
|
||||
|
||||
template<typename Storage, typename M>
|
||||
friend class FilePathCache;
|
||||
|
||||
public:
|
||||
using DirectoryPathCache = StringCache<Utils::PathString,
|
||||
Utils::SmallStringView,
|
||||
int,
|
||||
SharedMutex,
|
||||
Mutex,
|
||||
decltype(&Utils::reverseCompare),
|
||||
Utils::reverseCompare,
|
||||
Sources::Directory>;
|
||||
using FileNameCache = StringCache<FileNameEntry,
|
||||
FileNameView,
|
||||
int,
|
||||
SharedMutex,
|
||||
Mutex,
|
||||
decltype(&FileNameView::compare),
|
||||
FileNameView::compare,
|
||||
Sources::Source>;
|
||||
|
||||
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<typename Cache>
|
||||
Cache clone()
|
||||
{
|
||||
using DirectoryPathCache = typename Cache::DirectoryPathCache;
|
||||
using FileNameCache = typename Cache::FileNameCache;
|
||||
Cache cache{m_filePathStorage};
|
||||
cache.m_directoryPathCache = m_directoryPathCache.template clone<DirectoryPathCache>();
|
||||
cache.m_fileNameCache = m_fileNameCache.template clone<FileNameCache>();
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
FilePathId filePathId(FilePathView filePath) const
|
||||
{
|
||||
|
@@ -66,11 +66,11 @@ class CLANGSUPPORT_EXPORT CopyableFilePathCaching final : public FilePathCaching
|
||||
{
|
||||
using Factory = FilePathStorageSqliteStatementFactory<Sqlite::Database>;
|
||||
using Storage = FilePathStorage<Factory>;
|
||||
using Cache = FilePathCache<Storage>;
|
||||
using Cache = FilePathCache<Storage, NonLockingMutex>;
|
||||
|
||||
public:
|
||||
CopyableFilePathCaching(FilePathCaching &cache)
|
||||
: m_cache(cache.m_cache.clone())
|
||||
: m_cache(cache.m_cache.clone<Cache>())
|
||||
{}
|
||||
|
||||
FilePathId filePathId(FilePathView filePath) const override;
|
||||
|
@@ -101,6 +101,9 @@ template<typename StringType,
|
||||
typename CacheEntry = StringCacheEntry<StringType, StringViewType, IndexType>>
|
||||
class StringCache
|
||||
{
|
||||
template<typename T, typename V, typename I, typename M, typename C, C c, typename CE>
|
||||
friend class StringCache;
|
||||
|
||||
public:
|
||||
using CacheEntries = std::vector<CacheEntry>;
|
||||
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<typename Cache>
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user