]> git.lyx.org Git - features.git/commitdiff
Make include and bibitem insets threadsafe
authorGeorg Baum <baum@lyx.org>
Sat, 5 Jul 2014 10:09:49 +0000 (12:09 +0200)
committerGeorg Baum <baum@lyx.org>
Sat, 5 Jul 2014 10:09:49 +0000 (12:09 +0200)
Using a mutex to ensure that the generated filenames and ids are still unique.

src/insets/InsetBibitem.cpp
src/insets/InsetInclude.cpp

index 4f263e99decf7c02b72cdc5a65c48620ae61dc71..d0a28e73fe964d02965d168b1b6829fa78f51096 100644 (file)
@@ -41,6 +41,7 @@
 #include "support/docstream.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
+#include "support/mutex.h"
 
 using namespace std;
 using namespace lyx::support;
@@ -48,8 +49,8 @@ using namespace lyx::support;
 namespace lyx {
 
 
-// FIXME THREAD
 int InsetBibitem::key_counter = 0;
+static Mutex counter_mutex;
 docstring const key_prefix = from_ascii("key-");
 
 
@@ -57,8 +58,10 @@ InsetBibitem::InsetBibitem(Buffer * buf, InsetCommandParams const & p)
        : InsetCommand(buf, p)
 {
        buffer().invalidateBibinfoCache();
-       if (getParam("key").empty())
+       if (getParam("key").empty()) {
+               Mutex::Locker lock(&counter_mutex);
                setParam("key", key_prefix + convert<docstring>(++key_counter));
+       }
 }
 
 
@@ -196,6 +199,7 @@ void InsetBibitem::read(Lexer & lex)
 
        if (prefixIs(getParam("key"), key_prefix)) {
                int const key = convert<int>(getParam("key").substr(key_prefix.length()));
+               Mutex::Locker lock(&counter_mutex);
                key_counter = max(key_counter, key);
        }
 }
index ff4a3291eb7b35dee677ee276015bb4a559e381f..74946504439d2c0655eb76e0c93be8f65545d5e7 100644 (file)
@@ -60,6 +60,7 @@
 #include "support/lassert.h"
 #include "support/lstrings.h" // contains
 #include "support/lyxalgo.h"
+#include "support/mutex.h"
 
 #include "support/bind.h"
 
@@ -75,8 +76,9 @@ namespace {
 
 docstring const uniqueID()
 {
-       // FIXME THREAD
        static unsigned int seed = 1000;
+       static Mutex mutex;
+       Mutex::Locker lock(&mutex);
        return "file" + convert<docstring>(++seed);
 }