]> git.lyx.org Git - lyx.git/blobdiff - src/sgml.cpp
Account for old versions of Pygments
[lyx.git] / src / sgml.cpp
index fdd0ed7270cf32ed4ba5b706eb0622a553837024..2facb3ed539e280d459fed50a9f9fba1ba7f3b48 100644 (file)
@@ -27,7 +27,9 @@
 #include "support/lstrings.h"
 #include "support/textutils.h"
 
+#include <atomic>
 #include <map>
+#include <QThreadStorage>
 
 using namespace std;
 using namespace lyx::support;
@@ -104,10 +106,8 @@ docstring sgml::escapeString(docstring const & raw)
 
 docstring const sgml::uniqueID(docstring const & label)
 {
-       // FIXME THREAD
-       // It seems unlikely there could be a problem here,
-       // but we could have concurrent access, in principle.
-       static unsigned int seed = 1000;
+       // thread-safe
+       static atomic_uint seed(1000);
        return label + convert<docstring>(++seed);
 }
 
@@ -135,10 +135,11 @@ docstring sgml::cleanID(Buffer const & buf, OutputParams const & runparams,
 
        docstring content;
 
-       // FIXME THREAD
        typedef map<docstring, docstring> MangledMap;
-       static MangledMap mangledNames;
-       static int mangleID = 1;
+       static QThreadStorage<MangledMap> tMangledNames;
+       static QThreadStorage<int> tMangleID;
+
+       MangledMap & mangledNames = tMangledNames.localData();
 
        MangledMap::const_iterator const known = mangledNames.find(orig);
        if (known != mangledNames.end())
@@ -167,9 +168,10 @@ docstring sgml::cleanID(Buffer const & buf, OutputParams const & runparams,
                }
        }
 
-       if (mangle)
+       if (mangle) {
+               int & mangleID = tMangleID.localData();
                content += "-" + convert<docstring>(mangleID++);
-       else if (isDigitASCII(content[content.size() - 1]))
+       else if (isDigitASCII(content[content.size() - 1]))
                content += ".";
 
        mangledNames[orig] = content;