forked from qt-creator/qt-creator
qmake: fix file id mapping lifetime management
turns out that flushing the ids together with the ProFile cache was an
abysmal idea, as the latter expires after a few seconds after loading
the project, while references to the ProFiles (and thus the underlying
file ids) are kept for as long as the project stays loaded. the early
flush would cause re-use of the file ids, which would wreak all kinds of
havoc when re-loading projects.
instead, ref-count the vfs class based on its instances.
amends 60245e55d7
.
Task-number: QTCREATORBUG-20113
Change-Id: I7382a71af4d6a991156c05719deae9fb1e4fb278
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -166,7 +166,6 @@ void ProFileCacheManager::clear()
|
|||||||
// loop is concerned. Use a shared pointer once this is not true anymore.
|
// loop is concerned. Use a shared pointer once this is not true anymore.
|
||||||
delete m_cache;
|
delete m_cache;
|
||||||
m_cache = 0;
|
m_cache = 0;
|
||||||
QMakeVfs::clearIds();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProFileCacheManager::discardFiles(const QString &prefix, QMakeVfs *vfs)
|
void ProFileCacheManager::discardFiles(const QString &prefix, QMakeVfs *vfs)
|
||||||
|
@@ -49,11 +49,29 @@ QMakeVfs::QMakeVfs()
|
|||||||
#ifndef QT_NO_TEXTCODEC
|
#ifndef QT_NO_TEXTCODEC
|
||||||
m_textCodec = 0;
|
m_textCodec = 0;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef PROEVALUATOR_THREAD_SAFE
|
||||||
|
QMutexLocker locker(&s_mutex);
|
||||||
|
#endif
|
||||||
|
++s_refCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMakeVfs::~QMakeVfs()
|
||||||
|
{
|
||||||
|
#ifdef PROEVALUATOR_THREAD_SAFE
|
||||||
|
QMutexLocker locker(&s_mutex);
|
||||||
|
#endif
|
||||||
|
if (!--s_refCount) {
|
||||||
|
s_fileIdCounter = 0;
|
||||||
|
s_fileIdMap.clear();
|
||||||
|
s_idFileMap.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef PROPARSER_THREAD_SAFE
|
#ifdef PROPARSER_THREAD_SAFE
|
||||||
QMutex QMakeVfs::s_mutex;
|
QMutex QMakeVfs::s_mutex;
|
||||||
#endif
|
#endif
|
||||||
|
int QMakeVfs::s_refCount;
|
||||||
QAtomicInt QMakeVfs::s_fileIdCounter;
|
QAtomicInt QMakeVfs::s_fileIdCounter;
|
||||||
QHash<QString, int> QMakeVfs::s_fileIdMap;
|
QHash<QString, int> QMakeVfs::s_fileIdMap;
|
||||||
QHash<int, QString> QMakeVfs::s_idFileMap;
|
QHash<int, QString> QMakeVfs::s_idFileMap;
|
||||||
@@ -111,16 +129,6 @@ QString QMakeVfs::fileNameForId(int id)
|
|||||||
return s_idFileMap.value(id);
|
return s_idFileMap.value(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMakeVfs::clearIds()
|
|
||||||
{
|
|
||||||
#ifdef PROEVALUATOR_THREAD_SAFE
|
|
||||||
QMutexLocker locker(&s_mutex);
|
|
||||||
#endif
|
|
||||||
s_fileIdCounter = 0;
|
|
||||||
s_fileIdMap.clear();
|
|
||||||
s_idFileMap.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QMakeVfs::writeFile(int id, QIODevice::OpenMode mode, VfsFlags flags,
|
bool QMakeVfs::writeFile(int id, QIODevice::OpenMode mode, VfsFlags flags,
|
||||||
const QString &contents, QString *errStr)
|
const QString &contents, QString *errStr)
|
||||||
{
|
{
|
||||||
|
@@ -72,10 +72,10 @@ public:
|
|||||||
Q_DECLARE_FLAGS(VfsFlags, VfsFlag)
|
Q_DECLARE_FLAGS(VfsFlags, VfsFlag)
|
||||||
|
|
||||||
QMakeVfs();
|
QMakeVfs();
|
||||||
|
~QMakeVfs();
|
||||||
|
|
||||||
int idForFileName(const QString &fn, VfsFlags flags);
|
int idForFileName(const QString &fn, VfsFlags flags);
|
||||||
QString fileNameForId(int id);
|
QString fileNameForId(int id);
|
||||||
static void clearIds();
|
|
||||||
bool writeFile(int id, QIODevice::OpenMode mode, VfsFlags flags, const QString &contents, QString *errStr);
|
bool writeFile(int id, QIODevice::OpenMode mode, VfsFlags flags, const QString &contents, QString *errStr);
|
||||||
ReadResult readFile(int id, QString *contents, QString *errStr);
|
ReadResult readFile(int id, QString *contents, QString *errStr);
|
||||||
bool exists(const QString &fn, QMakeVfs::VfsFlags flags);
|
bool exists(const QString &fn, QMakeVfs::VfsFlags flags);
|
||||||
@@ -93,6 +93,7 @@ private:
|
|||||||
#ifdef PROEVALUATOR_THREAD_SAFE
|
#ifdef PROEVALUATOR_THREAD_SAFE
|
||||||
static QMutex s_mutex;
|
static QMutex s_mutex;
|
||||||
#endif
|
#endif
|
||||||
|
static int s_refCount;
|
||||||
static QAtomicInt s_fileIdCounter;
|
static QAtomicInt s_fileIdCounter;
|
||||||
// Qt Creator's ProFile cache is a singleton to maximize its cross-project
|
// Qt Creator's ProFile cache is a singleton to maximize its cross-project
|
||||||
// effectiveness (shared prf files from QtVersions).
|
// effectiveness (shared prf files from QtVersions).
|
||||||
|
Reference in New Issue
Block a user