From 4a2250a5d1dd551f43f75e54942ecbf0d5702080 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sat, 5 Jul 2014 11:55:35 +0200 Subject: [PATCH] Make Formats::isZippedFile() threadsafe 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Format.cpp b/src/Format.cpp index 063b683ea9..82712af0cd 100644 --- a/src/Format.cpp +++ b/src/Format.cpp @@ -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" @@ -503,14 +504,15 @@ struct ZippedInfo { }; -// FIXME THREAD /// Mapping absolute pathnames of files to their ZippedInfo metadata. static std::map 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::iterator it = zipped_.find(fname); if (it != zipped_.end() && it->second.timestamp == timestamp) return it->second.zipped;