]> git.lyx.org Git - features.git/commitdiff
Make Formats::isZippedFile() threadsafe
authorGeorg Baum <baum@lyx.org>
Mon, 7 Jul 2014 19:34:54 +0000 (21:34 +0200)
committerGeorg Baum <baum@lyx.org>
Mon, 7 Jul 2014 19:34:54 +0000 (21:34 +0200)
In this case I use a mutex, so the zip status of files is shared between
threads. This is possible because a deadlock can't happen, and it should give
better performance.

src/Format.cpp

index 2bc7ac534b745139e79e6282dbf0bd291c4a12c1..93383ac6c272464c2b615ea71fd7a4186ee78e3b 100644 (file)
@@ -22,6 +22,7 @@
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
+#include "support/mutex.h"
 #include "support/os.h"
 #include "support/PathChanger.h"
 #include "support/Systemcall.h"
@@ -479,11 +480,13 @@ struct ZippedInfo {
 
 /// Mapping absolute pathnames of files to their ZippedInfo metadata.
 static std::map<std::string, ZippedInfo> zipped_;
+static Mutex zipped_mutex;
 
 
 bool Formats::isZippedFile(support::FileName const & filename) const {
        string const & fname = filename.absFileName();
        time_t timestamp = filename.lastModified();
+       Mutex::Locker lock(&zipped_mutex);
        map<string, ZippedInfo>::iterator it = zipped_.find(fname);
        if (it != zipped_.end() && it->second.timestamp == timestamp)
                return it->second.zipped;