From: Georg Baum Date: Mon, 7 Jul 2014 20:03:32 +0000 (+0200) Subject: Make createBufferTmpDir() threadsafe X-Git-Tag: 2.1.2~50 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=fc3183a762c0f869b71f504c958bd646b7be85af;p=features.git Make createBufferTmpDir() threadsafe This must not use thread local storage, since the generated directories are all in the same parent directory which is unique per running LyX instance. --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index dcd74bcbb5..d629debf08 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -98,6 +98,7 @@ #include "support/gzstream.h" #include "support/lstrings.h" #include "support/lyxalgo.h" +#include "support/mutex.h" #include "support/os.h" #include "support/Package.h" #include "support/PathChanger.h" @@ -354,12 +355,20 @@ private: /// Creates the per buffer temporary directory static FileName createBufferTmpDir() { - static int count; + // FIXME This would be the ideal application for a TempDir class (like + // TempFile but for directories) + string counter; + { + static int count; + static Mutex mutex; + Mutex::Locker locker(&mutex); + counter = convert(count++); + } // We are in our own directory. Why bother to mangle name? // In fact I wrote this code to circumvent a problematic behaviour // (bug?) of EMX mkstemp(). FileName tmpfl(package().temp_dir().absFileName() + "/lyx_tmpbuf" + - convert(count++)); + counter); if (!tmpfl.createDirectory(0777)) { throw ExceptionMessage(WarningException, _("Disk Error: "), bformat(