From f12fd482f50fde77f11d3c45309d538c02b9d334 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 24 May 2018 20:50:32 +0200 Subject: 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. but just ref-counting the vfs class is insufficient as well, as then the ProFile cache (which expires after a timeout) could outlive all VFS instances and thus refer to ids which were discarded and later re-used. so we ref-count, and additionally let the cache instance hold a reference to the vfs class. this is sync-up with qt creator; no actual effect on qmake itself. amends 190aa94be. Change-Id: Idd4478ffc1c2405b3b83df32fba45b1f687f6a18 Reviewed-by: Robert Loehning Reviewed-by: Orgad Shaneh Reviewed-by: Eike Ziller Reviewed-by: Tobias Hunger (cherry picked from qtcreator/d03fb350672d311dccc06f0bcb4da744a3c99745) (cherry picked from qtcreator/1ddfb443b686ef04cc0e28363308ce70d01f0d73) Reviewed-by: Oswald Buddenhagen --- qmake/library/qmakevfs.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'qmake/library/qmakevfs.h') diff --git a/qmake/library/qmakevfs.h b/qmake/library/qmakevfs.h index 1217225471..68c21a3d37 100644 --- a/qmake/library/qmakevfs.h +++ b/qmake/library/qmakevfs.h @@ -76,10 +76,13 @@ public: Q_DECLARE_FLAGS(VfsFlags, VfsFlag) QMakeVfs(); + ~QMakeVfs(); + + static void ref(); + static void deref(); int idForFileName(const QString &fn, VfsFlags flags); QString fileNameForId(int id); - static void clearIds(); bool writeFile(int id, QIODevice::OpenMode mode, VfsFlags flags, const QString &contents, QString *errStr); ReadResult readFile(int id, QString *contents, QString *errStr); bool exists(const QString &fn, QMakeVfs::VfsFlags flags); @@ -97,6 +100,7 @@ private: #ifdef PROEVALUATOR_THREAD_SAFE static QMutex s_mutex; #endif + static int s_refCount; static QAtomicInt s_fileIdCounter; // Qt Creator's ProFile cache is a singleton to maximize its cross-project // effectiveness (shared prf files from QtVersions). -- cgit v1.2.3