]> git.lyx.org Git - lyx.git/commitdiff
Make BufferParams::auto_packages() threadsafe
authorGeorg Baum <baum@lyx.org>
Sat, 5 Jul 2014 10:39:59 +0000 (12:39 +0200)
committerGeorg Baum <baum@lyx.org>
Sat, 5 Jul 2014 10:39:59 +0000 (12:39 +0200)
src/BufferParams.cpp

index 49c55aaa511d6f52249d29b709a176d042a7c31a..792f14833fc435b32ae142c6cd6f6747ba1c0cc5 100644 (file)
@@ -52,6 +52,7 @@
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/Messages.h"
+#include "support/mutex.h"
 #include "support/Translator.h"
 #include "support/lstrings.h"
 
@@ -446,10 +447,16 @@ void BufferParams::use_package(std::string const & p, BufferParams::Package u)
 
 map<string, string> const & BufferParams::auto_packages()
 {
-       // FIXME THREAD
-       // It is extremely unlikely that there could be a problem here, but...
        static map<string, string> packages;
        if (packages.empty()) {
+               // We could have a race condition here that two threads
+               // discover an empty map at the same time and want to fill
+               // it, but that is no problem, since the same contents is
+               // filled in twice then. Having the locker inside the
+               // packages.empty() condition has the advantage that we
+               // don't need the mutex overhead for simple reading.
+               static Mutex mutex;
+               Mutex::Locker locker(&mutex);
                // adding a package here implies a file format change!
                packages["amsmath"] =
                        N_("The LaTeX package amsmath is only used if AMS formula types or symbols from the AMS math toolbars are inserted into formulas");