]> git.lyx.org Git - features.git/commitdiff
Make include and bibitem insets threadsafe
authorGeorg Baum <baum@lyx.org>
Mon, 7 Jul 2014 19:35:53 +0000 (21:35 +0200)
committerGeorg Baum <baum@lyx.org>
Mon, 7 Jul 2014 19:35:53 +0000 (21:35 +0200)
Using a mutex to ensure that the generated filenames and ids are still unique.

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

index 2840ad5c8fff621f51992f53c8595845513940d3..bf3929c79d1e087ab7a8206bf599ecc383538b70 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;
@@ -49,6 +50,7 @@ namespace lyx {
 
 
 int InsetBibitem::key_counter = 0;
+static Mutex counter_mutex;
 docstring const key_prefix = from_ascii("key-");
 
 
@@ -56,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));
+       }
 }
 
 
@@ -197,6 +201,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 d53166267b7aa1c3693a27d4405f60d9d5b0d1be..e3960c4f00cd58bcf7184acd31e94d0ddd2c6582 100644 (file)
@@ -61,6 +61,7 @@
 #include "support/lassert.h"
 #include "support/lstrings.h" // contains
 #include "support/lyxalgo.h"
+#include "support/mutex.h"
 
 #include "support/bind.h"
 
@@ -77,6 +78,8 @@ namespace {
 docstring const uniqueID()
 {
        static unsigned int seed = 1000;
+       static Mutex mutex;
+       Mutex::Locker lock(&mutex);
        return "file" + convert<docstring>(++seed);
 }