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 {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
template <typename FilePathStorage>
|
template<typename FilePathStorage, typename Mutex = SharedMutex>
|
||||||
class CLANGSUPPORT_GCCEXPORT FilePathCache
|
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,
|
using DirectoryPathCache = StringCache<Utils::PathString,
|
||||||
Utils::SmallStringView,
|
Utils::SmallStringView,
|
||||||
int,
|
int,
|
||||||
SharedMutex,
|
Mutex,
|
||||||
decltype(&Utils::reverseCompare),
|
decltype(&Utils::reverseCompare),
|
||||||
Utils::reverseCompare,
|
Utils::reverseCompare,
|
||||||
Sources::Directory>;
|
Sources::Directory>;
|
||||||
using FileNameCache = StringCache<FileNameEntry,
|
using FileNameCache = StringCache<FileNameEntry,
|
||||||
FileNameView,
|
FileNameView,
|
||||||
int,
|
int,
|
||||||
SharedMutex,
|
Mutex,
|
||||||
decltype(&FileNameView::compare),
|
decltype(&FileNameView::compare),
|
||||||
FileNameView::compare,
|
FileNameView::compare,
|
||||||
Sources::Source>;
|
Sources::Source>;
|
||||||
|
|
||||||
FilePathCache(const FilePathCache &) = default;
|
|
||||||
FilePathCache &operator=(const FilePathCache &) = default;
|
|
||||||
|
|
||||||
public:
|
|
||||||
FilePathCache(FilePathStorage &filePathStorage)
|
FilePathCache(FilePathStorage &filePathStorage)
|
||||||
: m_filePathStorage(filePathStorage)
|
: m_filePathStorage(filePathStorage)
|
||||||
{
|
{
|
||||||
@@ -69,7 +72,17 @@ public:
|
|||||||
FilePathCache(FilePathCache &&) = default;
|
FilePathCache(FilePathCache &&) = default;
|
||||||
FilePathCache &operator=(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
|
FilePathId filePathId(FilePathView filePath) const
|
||||||
{
|
{
|
||||||
|
@@ -66,11 +66,11 @@ class CLANGSUPPORT_EXPORT CopyableFilePathCaching final : public FilePathCaching
|
|||||||
{
|
{
|
||||||
using Factory = FilePathStorageSqliteStatementFactory<Sqlite::Database>;
|
using Factory = FilePathStorageSqliteStatementFactory<Sqlite::Database>;
|
||||||
using Storage = FilePathStorage<Factory>;
|
using Storage = FilePathStorage<Factory>;
|
||||||
using Cache = FilePathCache<Storage>;
|
using Cache = FilePathCache<Storage, NonLockingMutex>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CopyableFilePathCaching(FilePathCaching &cache)
|
CopyableFilePathCaching(FilePathCaching &cache)
|
||||||
: m_cache(cache.m_cache.clone())
|
: m_cache(cache.m_cache.clone<Cache>())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
FilePathId filePathId(FilePathView filePath) const override;
|
FilePathId filePathId(FilePathView filePath) const override;
|
||||||
|
@@ -101,6 +101,9 @@ template<typename StringType,
|
|||||||
typename CacheEntry = StringCacheEntry<StringType, StringViewType, IndexType>>
|
typename CacheEntry = StringCacheEntry<StringType, StringViewType, IndexType>>
|
||||||
class StringCache
|
class StringCache
|
||||||
{
|
{
|
||||||
|
template<typename T, typename V, typename I, typename M, typename C, C c, typename CE>
|
||||||
|
friend class StringCache;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using CacheEntries = std::vector<CacheEntry>;
|
using CacheEntries = std::vector<CacheEntry>;
|
||||||
using const_iterator = typename CacheEntries::const_iterator;
|
using const_iterator = typename CacheEntries::const_iterator;
|
||||||
@@ -116,13 +119,27 @@ public:
|
|||||||
: m_strings(other.m_strings)
|
: m_strings(other.m_strings)
|
||||||
, m_indices(other.m_indices)
|
, m_indices(other.m_indices)
|
||||||
{}
|
{}
|
||||||
StringCache &operator=(const StringCache &other)
|
|
||||||
|
template<typename Cache>
|
||||||
|
Cache clone()
|
||||||
{
|
{
|
||||||
if (*this != other) {
|
Cache cache;
|
||||||
m_strings = other.m_strings;
|
cache.m_strings = m_strings;
|
||||||
m_indices = other.m_indices;
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user