]> git.lyx.org Git - lyx.git/commitdiff
Make createBufferTmpDir() threadsafe
authorGeorg Baum <baum@lyx.org>
Sat, 5 Jul 2014 10:31:12 +0000 (12:31 +0200)
committerGeorg Baum <baum@lyx.org>
Sat, 5 Jul 2014 10:31:12 +0000 (12:31 +0200)
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.

src/Buffer.cpp

index 4331309857d5420088394f9c0c9389fac1549c9e..0a362c3ef4d857b92f3ee02d34c79960869d586a 100644 (file)
@@ -97,6 +97,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"
@@ -353,13 +354,20 @@ private:
 /// Creates the per buffer temporary directory
 static FileName createBufferTmpDir()
 {
-       // FIXME THREAD
-       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<string>(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<string>(count++));
+               counter);
 
        if (!tmpfl.createDirectory(0777)) {
                throw ExceptionMessage(WarningException, _("Disk Error: "), bformat(