[poppler] 2 commits - CMakeLists.txt config.h.cmake goo/GooMutex.h poppler/Annot.cc poppler/Annot.h poppler/Array.cc poppler/Array.h poppler/CairoFontEngine.cc poppler/CairoFontEngine.h poppler/Catalog.cc poppler/Catalog.h poppler/CharCodeToUnicode.cc poppler/CharCodeToUnicode.h poppler/CMap.cc poppler/CMap.h poppler/Dict.cc poppler/Dict.h poppler/GlobalParams.cc poppler/GlobalParams.h poppler/GlobalParamsWin.cc poppler/Page.cc poppler/Page.h poppler/PDFDoc.cc poppler/PDFDoc.h poppler/poppler-config.h.cmake poppler/Stream.cc poppler/Stream.h poppler/XRef.cc poppler/XRef.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Sep 21 22:39:50 UTC 2018


 CMakeLists.txt                 |    5 -
 config.h.cmake                 |    3 
 goo/GooMutex.h                 |   93 ------------------
 poppler/Annot.cc               |   29 -----
 poppler/Annot.h                |    9 +
 poppler/Array.cc               |   25 -----
 poppler/Array.h                |   14 +-
 poppler/CMap.cc                |   26 -----
 poppler/CMap.h                 |   11 --
 poppler/CairoFontEngine.cc     |   14 --
 poppler/CairoFontEngine.h      |    6 -
 poppler/Catalog.cc             |   13 --
 poppler/Catalog.h              |    5 -
 poppler/CharCodeToUnicode.cc   |   29 -----
 poppler/CharCodeToUnicode.h    |   11 --
 poppler/Dict.cc                |   19 ---
 poppler/Dict.h                 |    9 -
 poppler/GlobalParams.cc        |  203 +++++++++++------------------------------
 poppler/GlobalParams.h         |   13 --
 poppler/GlobalParamsWin.cc     |   20 ----
 poppler/PDFDoc.cc              |   14 --
 poppler/PDFDoc.h               |    7 -
 poppler/Page.cc                |   13 --
 poppler/Page.h                 |    7 -
 poppler/Stream.cc              |   26 -----
 poppler/Stream.h               |   14 +-
 poppler/XRef.cc                |   24 ----
 poppler/XRef.h                 |    5 -
 poppler/poppler-config.h.cmake |    5 -
 29 files changed, 121 insertions(+), 551 deletions(-)

New commits:
commit e5aff4b4fcbd3e1cbdd7d6329c00eee10b36e94d
Author: Adam Reichold <adam.reichold at t-online.de>
Date:   Fri Sep 21 16:31:27 2018 +0200

    Remove MULTITHREADED build flag, i.e. always enable threading support based on the C++ standard library and make use of RAII lockers for GlobalParams.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f5f9ced3..56036307 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -109,10 +109,6 @@ else()
   message(FATAL_ERROR "Invalid font configuration setting: ${FONT_CONFIGURATION}")
 endif()
 
-if(CMAKE_USE_PTHREADS_INIT OR WIN32)
-  set(MULTITHREADED ON)
-endif()
-
 # Enable these unconditionally.
 set(OPI_SUPPORT ON)
 set(TEXTOUT_WORD_LIST ON)
diff --git a/config.h.cmake b/config.h.cmake
index 10ce5580..194ccc41 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -126,9 +126,6 @@
 /* Define as const if the declaration of iconv() needs const. */
 #define ICONV_CONST ${ICONV_CONST}
 
-/* Enable multithreading support. */
-#cmakedefine MULTITHREADED 1
-
 /* Generate OPI comments in PS output. */
 #cmakedefine OPI_SUPPORT 1
 
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 392aa5ba..a58ad36c 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -82,12 +82,6 @@
 #include <string.h>
 #include <algorithm>
 
-#ifdef MULTITHREADED
-#  define annotLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
-#else
-#  define annotLocker()
-#endif
-
 #define fieldFlagReadOnly           0x00000001
 #define fieldFlagRequired           0x00000002
 #define fieldFlagNoExport           0x00000004
@@ -1220,6 +1214,8 @@ double AnnotAppearanceBBox::getPageYMax() const {
 // Annot
 //------------------------------------------------------------------------
 
+#define annotLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
+
 Annot::Annot(PDFDoc *docA, PDFRectangle *rectA) {
 
   refCnt = 1;
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 33c2b65c..5b04e982 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -769,9 +769,7 @@ protected:
   GBool ok;
 
   bool hasRef;
-#ifdef MULTITHREADED
   mutable std::recursive_mutex mutex;
-#endif
 };
 
 //------------------------------------------------------------------------
diff --git a/poppler/Array.cc b/poppler/Array.cc
index c6df8581..33f6e458 100644
--- a/poppler/Array.cc
+++ b/poppler/Array.cc
@@ -38,15 +38,12 @@
 #include "Object.h"
 #include "Array.h"
 
-#ifdef MULTITHREADED
-#  define arrayLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
-#else
-#  define arrayLocker()
-#endif
 //------------------------------------------------------------------------
 // Array
 //------------------------------------------------------------------------
 
+#define arrayLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
+
 Array::Array(XRef *xrefA) {
   xref = xrefA;
   elems = nullptr;
diff --git a/poppler/Array.h b/poppler/Array.h
index d7ba1851..ff8755cf 100644
--- a/poppler/Array.h
+++ b/poppler/Array.h
@@ -85,9 +85,7 @@ private:
   int size;			// size of <elems> array
   int length;			// number of elements in array
   std::atomic_int ref;			// reference count
-#ifdef MULTITHREADED
   mutable std::recursive_mutex mutex;
-#endif
 };
 
 #endif
diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
index b95348bf..b150b0bb 100644
--- a/poppler/CairoFontEngine.cc
+++ b/poppler/CairoFontEngine.cc
@@ -60,12 +60,6 @@
 #pragma implementation
 #endif
 
-#ifdef MULTITHREADED
-#  define fontEngineLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
-#else
-#  define fontEngineLocker()
-#endif
-
 //------------------------------------------------------------------------
 // CairoFont
 //------------------------------------------------------------------------
@@ -802,6 +796,8 @@ CairoType3Font::matches(Ref &other, GBool printingA) {
 // CairoFontEngine
 //------------------------------------------------------------------------
 
+#define fontEngineLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
+
 CairoFontEngine::CairoFontEngine(FT_Library libA) {
   int i;
 
diff --git a/poppler/CairoFontEngine.h b/poppler/CairoFontEngine.h
index 909e2224..60410099 100644
--- a/poppler/CairoFontEngine.h
+++ b/poppler/CairoFontEngine.h
@@ -127,9 +127,7 @@ private:
   CairoFont *fontCache[cairoFontCacheSize];
   FT_Library lib;
   GBool useCIDs;
-#ifdef MULTITHREADED
   mutable std::recursive_mutex mutex;
-#endif
 };
 
 #endif
diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc
index df692fd6..d9edf6b1 100644
--- a/poppler/Catalog.cc
+++ b/poppler/Catalog.cc
@@ -66,15 +66,12 @@
 #include "FileSpec.h"
 #include "StructTreeRoot.h"
 
-#ifdef MULTITHREADED
-#  define catalogLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
-#else
-#  define catalogLocker()
-#endif
 //------------------------------------------------------------------------
 // Catalog
 //------------------------------------------------------------------------
 
+#define catalogLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
+
 Catalog::Catalog(PDFDoc *docA) {
   ok = gTrue;
   doc = docA;
diff --git a/poppler/Catalog.h b/poppler/Catalog.h
index 869d16cf..ed058f31 100644
--- a/poppler/Catalog.h
+++ b/poppler/Catalog.h
@@ -291,10 +291,8 @@ private:
   NameTree *getEmbeddedFileNameTree();
   NameTree *getJSNameTree();
   LinkDest *createLinkDest(Object *obj);
-#ifdef MULTITHREADED
-  mutable std::recursive_mutex mutex;
-#endif
 
+  mutable std::recursive_mutex mutex;
 };
 
 #endif
diff --git a/poppler/Dict.cc b/poppler/Dict.cc
index 2e013c78..3e14a50d 100644
--- a/poppler/Dict.cc
+++ b/poppler/Dict.cc
@@ -40,15 +40,12 @@
 #include "XRef.h"
 #include "Dict.h"
 
-#ifdef MULTITHREADED
-#  define dictLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
-#else
-#  define dictLocker()
-#endif
 //------------------------------------------------------------------------
 // Dict
 //------------------------------------------------------------------------
 
+#define dictLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
+
 constexpr int SORT_LENGTH_LOWER_LIMIT = 32;
 
 struct Dict::CmpDictEntry {
diff --git a/poppler/Dict.h b/poppler/Dict.h
index 8271c830..20fd8455 100644
--- a/poppler/Dict.h
+++ b/poppler/Dict.h
@@ -111,9 +111,7 @@ private:
   XRef *xref;			// the xref table for this PDF file
   std::vector<DictEntry> entries;
   std::atomic_int ref;			// reference count
-#ifdef MULTITHREADED
   mutable std::recursive_mutex mutex;
-#endif
 
   const DictEntry *find(const char *key) const;
   DictEntry *find(const char *key);
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 410b3965..4671495e 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -92,22 +92,6 @@
 #  include <strings.h>
 #endif
 
-#ifdef MULTITHREADED
-#  define lockGlobalParams            mutex.lock()
-#  define lockUnicodeMapCache         unicodeMapCacheMutex.lock()
-#  define lockCMapCache               cMapCacheMutex.lock()
-#  define unlockGlobalParams          mutex.unlock()
-#  define unlockUnicodeMapCache       unicodeMapCacheMutex.unlock()
-#  define unlockCMapCache             cMapCacheMutex.unlock()
-#else
-#  define lockGlobalParams
-#  define lockUnicodeMapCache
-#  define lockCMapCache
-#  define unlockGlobalParams
-#  define unlockUnicodeMapCache
-#  define unlockCMapCache
-#endif
-
 #ifndef FC_WEIGHT_BOOK
 #define FC_WEIGHT_BOOK 75
 #endif
@@ -543,6 +527,10 @@ Plugin::~Plugin() {
 
 #endif // ENABLE_PLUGINS
 
+#define globalParamsLocker()	std::unique_lock<std::recursive_mutex> locker(mutex)
+#define unicodeMapCacheLocker()	std::unique_lock<std::recursive_mutex> locker(unicodeMapCacheMutex)
+#define cMapCacheLocker()	std::unique_lock<std::recursive_mutex> locker(cMapCacheMutex)
+
 //------------------------------------------------------------------------
 // parsing
 //------------------------------------------------------------------------
@@ -768,13 +756,12 @@ Unicode GlobalParams::mapNameToUnicodeText(const char *charName) {
 UnicodeMap *GlobalParams::getResidentUnicodeMap(GooString *encodingName) {
   UnicodeMap *map = nullptr;
 
-  lockGlobalParams;
+  globalParamsLocker();
   const auto unicodeMap = residentUnicodeMaps.find(encodingName->toStr());
   if (unicodeMap != residentUnicodeMaps.end()) {
     map = &unicodeMap->second;
     map->incRefCnt();
   }
-  unlockGlobalParams;
 
   return map;
 }
@@ -782,12 +769,11 @@ UnicodeMap *GlobalParams::getResidentUnicodeMap(GooString *encodingName) {
 FILE *GlobalParams::getUnicodeMapFile(GooString *encodingName) {
   FILE *file = nullptr;
 
-  lockGlobalParams;
+  globalParamsLocker();
   const auto unicodeMap = unicodeMaps.find(encodingName->toStr());
   if (unicodeMap != unicodeMaps.end()) {
     file = openFile(unicodeMap->second.c_str(), "r");
   }
-  unlockGlobalParams;
 
   return file;
 }
@@ -795,7 +781,7 @@ FILE *GlobalParams::getUnicodeMapFile(GooString *encodingName) {
 FILE *GlobalParams::findCMapFile(GooString *collection, GooString *cMapName) {
   FILE *file = nullptr;
 
-  lockGlobalParams;
+  globalParamsLocker();
   const auto cMapDirs = this->cMapDirs.equal_range(collection->toStr());
   for (auto cMapDir = cMapDirs.first; cMapDir != cMapDirs.second; ++cMapDir) {
     auto* const path = new GooString(cMapDir->second);
@@ -806,7 +792,7 @@ FILE *GlobalParams::findCMapFile(GooString *collection, GooString *cMapName) {
       break;
     }
   }
-  unlockGlobalParams;
+
   return file;
 }
 
@@ -815,18 +801,16 @@ FILE *GlobalParams::findToUnicodeFile(GooString *name) {
   FILE *f;
   int i;
 
-  lockGlobalParams;
+  globalParamsLocker();
   for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
     dir = (GooString *)toUnicodeDirs->get(i);
     fileName = appendToPath(dir->copy(), name->getCString());
     f = openFile(fileName->getCString(), "r");
     delete fileName;
     if (f) {
-      unlockGlobalParams;
       return f;
     }
   }
-  unlockGlobalParams;
   return nullptr;
 }
 
@@ -1008,12 +992,12 @@ GooString *GlobalParams::findFontFile(GooString *fontName) {
   GooString *path = nullptr;
 
   setupBaseFonts(nullptr);
-  lockGlobalParams;
+  globalParamsLocker();
   const auto fontFile = fontFiles.find(fontName->toStr());
   if (fontFile != fontFiles.end()) {
     path = new GooString(fontFile->second);
   }
-  unlockGlobalParams;
+
   return path;
 }
 
@@ -1041,7 +1025,8 @@ GooString *GlobalParams::findSystemFontFile(GfxFont *font,
   const GooString *fontName = font->getName();
   GooString substituteName;
   if (!fontName) return nullptr;
-  lockGlobalParams;
+
+  globalParamsLocker();
 
   if ((fi = sysFonts->find(fontName, font->isFixedWidth(), gTrue))) {
     path = fi->path->copy();
@@ -1190,7 +1175,7 @@ GooString *GlobalParams::findSystemFontFile(GfxFont *font,
 fin:
   if (p)
     FcPatternDestroy(p);
-  unlockGlobalParams;
+
   return path;
 }
 
@@ -1289,96 +1274,60 @@ GooString *GlobalParams::findSystemFontFile(GfxFont *font,
   if (!fontName) return nullptr;
 
   path = NULL;
-  lockGlobalParams;
+  globalParamsLocker();
   if ((fi = sysFonts->find(fontName, font->isFixedWidth(), gFalse))) {
     path = fi->path->copy();
     *type = fi->type;
     *fontNum = fi->fontNum;
   }
-  unlockGlobalParams; 
+
   return path;
 }
 #endif
 
 GBool GlobalParams::getPSExpandSmaller() {
-  GBool f;
-
-  lockGlobalParams;
-  f = psExpandSmaller;
-  unlockGlobalParams;
-  return f;
+  globalParamsLocker();
+  return psExpandSmaller;
 }
 
 GBool GlobalParams::getPSShrinkLarger() {
-  GBool f;
-
-  lockGlobalParams;
-  f = psShrinkLarger;
-  unlockGlobalParams;
-  return f;
+  globalParamsLocker();
+  return psShrinkLarger;
 }
 
 PSLevel GlobalParams::getPSLevel() {
-  PSLevel level;
-
-  lockGlobalParams;
-  level = psLevel;
-  unlockGlobalParams;
-  return level;
+  globalParamsLocker();
+  return psLevel;
 }
 
 GooString *GlobalParams::getTextEncodingName() {
-  GooString *s;
-
-  lockGlobalParams;
-  s = textEncoding->copy();
-  unlockGlobalParams;
-  return s;
+  globalParamsLocker();
+  return textEncoding->copy();
 }
 
 EndOfLineKind GlobalParams::getTextEOL() {
-  EndOfLineKind eol;
-
-  lockGlobalParams;
-  eol = textEOL;
-  unlockGlobalParams;
-  return eol;
+  globalParamsLocker();
+  return textEOL;
 }
 
 GBool GlobalParams::getTextPageBreaks() {
-  GBool pageBreaks;
-
-  lockGlobalParams;
-  pageBreaks = textPageBreaks;
-  unlockGlobalParams;
-  return pageBreaks;
+  globalParamsLocker();
+  return textPageBreaks;
 }
 
 GBool GlobalParams::getEnableFreeType() {
-  GBool f;
-
-  lockGlobalParams;
-  f = enableFreeType;
-  unlockGlobalParams;
-  return f;
+  globalParamsLocker();
+  return enableFreeType;
 }
 
 GBool GlobalParams::getPrintCommands() {
-  GBool p;
-
-  lockGlobalParams;
-  p = printCommands;
-  unlockGlobalParams;
-  return p;
+  globalParamsLocker();
+  return printCommands;
 }
 
 GBool GlobalParams::getProfileCommands() {
-  GBool p;
-
-  lockGlobalParams;
-  p = profileCommands;
-  unlockGlobalParams;
-  return p;
+  globalParamsLocker();
+  return profileCommands;
 }
 
 GBool GlobalParams::getErrQuiet() {
@@ -1390,7 +1339,7 @@ GBool GlobalParams::getErrQuiet() {
 CharCodeToUnicode *GlobalParams::getCIDToUnicode(GooString *collection) {
   CharCodeToUnicode *ctu;
 
-  lockGlobalParams;
+  globalParamsLocker();
   if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) {
     const auto cidToUnicode = cidToUnicodes.find(collection->toStr());
     if (cidToUnicode != cidToUnicodes.end()) {
@@ -1399,7 +1348,7 @@ CharCodeToUnicode *GlobalParams::getCIDToUnicode(GooString *collection) {
       }
     }
   }
-  unlockGlobalParams;
+
   return ctu;
 }
 
@@ -1411,20 +1360,16 @@ UnicodeMap *GlobalParams::getUnicodeMap2(GooString *encodingName) {
   UnicodeMap *map;
 
   if (!(map = getResidentUnicodeMap(encodingName))) {
-    lockUnicodeMapCache;
+    unicodeMapCacheLocker();
     map = unicodeMapCache->getUnicodeMap(encodingName);
-    unlockUnicodeMapCache;
   }
+
   return map;
 }
 
 CMap *GlobalParams::getCMap(GooString *collection, GooString *cMapName, Stream *stream) {
-  CMap *cMap;
-
-  lockCMapCache;
-  cMap = cMapCache->getCMap(collection, cMapName, stream);
-  unlockCMapCache;
-  return cMap;
+  cMapCacheLocker();
+  return cMapCache->getCMap(collection, cMapName, stream);
 }
 
 UnicodeMap *GlobalParams::getTextEncoding() {
@@ -1448,38 +1393,33 @@ GooList *GlobalParams::getEncodingNames()
 //------------------------------------------------------------------------
 
 void GlobalParams::addFontFile(GooString *fontName, GooString *path) {
-  lockGlobalParams;
+  globalParamsLocker();
   fontFiles[fontName->toStr()] = path->toStr();
-  unlockGlobalParams;
 }
 
 void GlobalParams::setPSExpandSmaller(GBool expand) {
-  lockGlobalParams;
+  globalParamsLocker();
   psExpandSmaller = expand;
-  unlockGlobalParams;
 }
 
 void GlobalParams::setPSShrinkLarger(GBool shrink) {
-  lockGlobalParams;
+  globalParamsLocker();
   psShrinkLarger = shrink;
-  unlockGlobalParams;
 }
 
 void GlobalParams::setPSLevel(PSLevel level) {
-  lockGlobalParams;
+  globalParamsLocker();
   psLevel = level;
-  unlockGlobalParams;
 }
 
 void GlobalParams::setTextEncoding(char *encodingName) {
-  lockGlobalParams;
+  globalParamsLocker();
   delete textEncoding;
   textEncoding = new GooString(encodingName);
-  unlockGlobalParams;
 }
 
 GBool GlobalParams::setTextEOL(char *s) {
-  lockGlobalParams;
+  globalParamsLocker();
   if (!strcmp(s, "unix")) {
     textEOL = eolUnix;
   } else if (!strcmp(s, "dos")) {
@@ -1487,57 +1427,45 @@ GBool GlobalParams::setTextEOL(char *s) {
   } else if (!strcmp(s, "mac")) {
     textEOL = eolMac;
   } else {
-    unlockGlobalParams;
     return gFalse;
   }
-  unlockGlobalParams;
   return gTrue;
 }
 
 void GlobalParams::setTextPageBreaks(GBool pageBreaks) {
-  lockGlobalParams;
+  globalParamsLocker();
   textPageBreaks = pageBreaks;
-  unlockGlobalParams;
 }
 
 GBool GlobalParams::setEnableFreeType(char *s) {
-  GBool ok;
-
-  lockGlobalParams;
-  ok = parseYesNo2(s, &enableFreeType);
-  unlockGlobalParams;
-  return ok;
+  globalParamsLocker();
+  return parseYesNo2(s, &enableFreeType);
 }
 
 void GlobalParams::setOverprintPreview(GBool overprintPreviewA) {
-  lockGlobalParams;
+  globalParamsLocker();
   overprintPreview = overprintPreviewA;
-  unlockGlobalParams;
 }
 
 void GlobalParams::setPrintCommands(GBool printCommandsA) {
-  lockGlobalParams;
+  globalParamsLocker();
   printCommands = printCommandsA;
-  unlockGlobalParams;
 }
 
 void GlobalParams::setProfileCommands(GBool profileCommandsA) {
-  lockGlobalParams;
+  globalParamsLocker();
   profileCommands = profileCommandsA;
-  unlockGlobalParams;
 }
 
 void GlobalParams::setErrQuiet(GBool errQuietA) {
-  lockGlobalParams;
+  globalParamsLocker();
   errQuiet = errQuietA;
-  unlockGlobalParams;
 }
 
 void GlobalParams::addSecurityHandler(XpdfSecurityHandler *handler) {
 #ifdef ENABLE_PLUGINS
-  lockGlobalParams;
+  globalParamsLocker();
   securityHandlers->append(handler);
-  unlockGlobalParams;
 #endif
 }
 
@@ -1546,29 +1474,25 @@ XpdfSecurityHandler *GlobalParams::getSecurityHandler(char *name) {
   XpdfSecurityHandler *hdlr;
   int i;
 
-  lockGlobalParams;
+  globalParamsLocker();
   for (i = 0; i < securityHandlers->getLength(); ++i) {
     hdlr = (XpdfSecurityHandler *)securityHandlers->get(i);
     if (!strcasecmp(hdlr->name, name)) {
-      unlockGlobalParams;
       return hdlr;
     }
   }
-  unlockGlobalParams;
 
   if (!loadPlugin("security", name)) {
     return NULL;
   }
 
-  lockGlobalParams;
+  globalParamsLocker();
   for (i = 0; i < securityHandlers->getLength(); ++i) {
     hdlr = (XpdfSecurityHandler *)securityHandlers->get(i);
     if (!strcmp(hdlr->name, name)) {
-      unlockGlobalParams;
       return hdlr;
     }
   }
-  unlockGlobalParams;
 #else
   (void)name;
 #endif
@@ -1587,9 +1511,8 @@ GBool GlobalParams::loadPlugin(char *type, char *name) {
   if (!(plugin = Plugin::load(type, name))) {
     return gFalse;
   }
-  lockGlobalParams;
+  globalParamsLocker();
   plugins->append(plugin);
-  unlockGlobalParams;
   return gTrue;
 }
 
diff --git a/poppler/GlobalParams.h b/poppler/GlobalParams.h
index 4c21ba39..8c4b6a31 100644
--- a/poppler/GlobalParams.h
+++ b/poppler/GlobalParams.h
@@ -242,11 +242,9 @@ private:
 				//   [XpdfSecurityHandler]
 #endif
 
-#ifdef MULTITHREADED
   mutable std::recursive_mutex mutex;
   mutable std::recursive_mutex unicodeMapCacheMutex;
   mutable std::recursive_mutex cMapCacheMutex;
-#endif
 
   const char *popplerDataDir;
 };
diff --git a/poppler/GlobalParamsWin.cc b/poppler/GlobalParamsWin.cc
index 9e041777..5561f531 100644
--- a/poppler/GlobalParamsWin.cc
+++ b/poppler/GlobalParamsWin.cc
@@ -54,22 +54,6 @@ description for all fonts available in Windows. That's how MuPDF works.
 #include "Lexer.h"
 #include "Parser.h"
 
-#ifdef MULTITHREADED
-#  define lockGlobalParams            gLockMutex(&mutex)
-#  define lockUnicodeMapCache         gLockMutex(&unicodeMapCacheMutex)
-#  define lockCMapCache               gLockMutex(&cMapCacheMutex)
-#  define unlockGlobalParams          gUnlockMutex(&mutex)
-#  define unlockUnicodeMapCache       gUnlockMutex(&unicodeMapCacheMutex)
-#  define unlockCMapCache             gUnlockMutex(&cMapCacheMutex)
-#else
-#  define lockGlobalParams
-#  define lockUnicodeMapCache
-#  define lockCMapCache
-#  define unlockGlobalParams
-#  define unlockUnicodeMapCache
-#  define unlockCMapCache
-#endif
-
 #define DEFAULT_SUBSTITUTE_FONT "Helvetica"
 #define DEFAULT_CID_FONT_AC1_MSWIN "MingLiU"   /* Adobe-CNS1 for Taiwan, HongKong */
 #define DEFAULT_CID_FONT_AG1_MSWIN "SimSun"    /* Adobe-GB1 for PRC, Singapore */
@@ -556,7 +540,7 @@ GooString *GlobalParams::findSystemFontFile(GfxFont *font,
   GooString *path = nullptr;
   const GooString *fontName = font->getName();
   if (!fontName) return nullptr;
-  lockGlobalParams;
+  std::unique_lock<std::recursive_mutex> locker(mutex);
   setupBaseFonts(nullptr);
 
   // TODO: base14Name should be changed?
@@ -587,6 +571,6 @@ GooString *GlobalParams::findSystemFontFile(GfxFont *font,
       *fontNum = 0;
     }
   }
-  unlockGlobalParams;
+
   return path;
 }
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index d8b39a75..b0f8a197 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -91,12 +91,6 @@
 #include "Hints.h"
 #include "UTF.h"
 
-#ifdef MULTITHREADED
-#  define pdfdocLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
-#else
-#  define pdfdocLocker()
-#endif
-
 //------------------------------------------------------------------------
 
 #define headerSearchSize 1024	// read this many bytes at beginning of
@@ -114,6 +108,8 @@
 // PDFDoc
 //------------------------------------------------------------------------
 
+#define pdfdocLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
+
 void PDFDoc::init()
 {
   ok = gFalse;
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index 1017eaca..11cd4591 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -433,9 +433,7 @@ private:
   int fopenErrno;
 
   Goffset startXRefPos;		// offset of last xref table
-#ifdef MULTITHREADED
   mutable std::recursive_mutex mutex;
-#endif
 };
 
 #endif
diff --git a/poppler/Page.cc b/poppler/Page.cc
index ce69c582..f460b7ed 100644
--- a/poppler/Page.cc
+++ b/poppler/Page.cc
@@ -61,11 +61,6 @@
 #include "Catalog.h"
 #include "Form.h"
 
-#ifdef MULTITHREADED
-#  define pageLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
-#else
-#  define pageLocker()
-#endif
 //------------------------------------------------------------------------
 // PDFRectangle
 //------------------------------------------------------------------------
@@ -248,6 +243,8 @@ GBool PageAttrs::readBox(Dict *dict, const char *key, PDFRectangle *box) {
 // Page
 //------------------------------------------------------------------------
 
+#define pageLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
+
 Page::Page(PDFDoc *docA, int numA, Object *pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form) {
   ok = gTrue;
   doc = docA;
diff --git a/poppler/Page.h b/poppler/Page.h
index 2d565e5d..b5559811 100644
--- a/poppler/Page.h
+++ b/poppler/Page.h
@@ -286,9 +286,7 @@ private:
   Object actions;		// page additional actions
   double duration;              // page duration
   GBool ok;			// true if page is valid
-#ifdef MULTITHREADED
   mutable std::recursive_mutex mutex;
-#endif
 };
 
 #endif
diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index 18e3d337..1dac5216 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -72,12 +72,6 @@
 #define permHighResPrint  (1<<11) // bit 12
 #define defPermFlags 0xfffc
 
-#ifdef MULTITHREADED
-#  define xrefLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
-#else
-#  define xrefLocker()
-#endif
-
 //------------------------------------------------------------------------
 // ObjectStream
 //------------------------------------------------------------------------
@@ -262,6 +256,8 @@ Object ObjectStream::getObject(int objIdx, int objNum) {
 // XRef
 //------------------------------------------------------------------------
 
+#define xrefLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
+
 void XRef::init() {
   ok = gTrue;
   errCode = errNone;
@@ -1233,15 +1229,11 @@ Object XRef::fetch(int num, int gen, int recursion) {
 }
 
 void XRef::lock() {
-#ifdef MULTITHREADED
   mutex.lock();
-#endif
 }
 
 void XRef::unlock() {
-#ifdef MULTITHREADED
   mutex.unlock();
-#endif
 }
 
 Object XRef::getDocInfo() {
diff --git a/poppler/XRef.h b/poppler/XRef.h
index 68c507ac..4facedc9 100644
--- a/poppler/XRef.h
+++ b/poppler/XRef.h
@@ -237,9 +237,7 @@ private:
   Goffset mainXRefOffset;	// position of the main XRef table/stream
   GBool scannedSpecialFlags;	// true if scanSpecialFlags has been called
   GBool strOwner;     // true if str is owned by the instance
-#ifdef MULTITHREADED
   mutable std::recursive_mutex mutex;
-#endif
 
   void init();
   int reserve(int newSize);
diff --git a/poppler/poppler-config.h.cmake b/poppler/poppler-config.h.cmake
index 20e3dd38..bd93f282 100644
--- a/poppler/poppler-config.h.cmake
+++ b/poppler/poppler-config.h.cmake
@@ -37,11 +37,6 @@
 #define POPPLER_VERSION "${POPPLER_VERSION}"
 #endif
 
-/* Enable multithreading support. */
-#ifndef MULTITHREADED
-#cmakedefine MULTITHREADED 1
-#endif
-
 /* Use fixedpoint. */
 #ifndef USE_FIXEDPOINT
 #cmakedefine USE_FIXEDPOINT 1
commit a38895a1851d9a7a9abd1070bba23fb68708cb78
Author: Adam Reichold <adam.reichold at t-online.de>
Date:   Sat Sep 1 07:20:32 2018 +0200

    Replace GooMutex by std::recursive_mutex (and plain reference counter by std::atomic_int).

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b664e5f3..f5f9ced3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -578,7 +578,6 @@ if(ENABLE_XPDF_HEADERS)
   install(FILES
     goo/GooList.h
     goo/GooTimer.h
-    goo/GooMutex.h
     goo/GooString.h
     goo/gtypes.h
     goo/gmem.h
diff --git a/goo/GooMutex.h b/goo/GooMutex.h
deleted file mode 100644
index ed0758fa..00000000
--- a/goo/GooMutex.h
+++ /dev/null
@@ -1,93 +0,0 @@
-//========================================================================
-//
-// GooMutex.h
-//
-// Portable mutex macros.
-//
-// Copyright 2002-2003 Glyph & Cog, LLC
-//
-//========================================================================
-
-//========================================================================
-//
-// Modified under the Poppler project - http://poppler.freedesktop.org
-//
-// All changes made under the Poppler project to this file are licensed
-// under GPL version 2 or later
-//
-// Copyright (C) 2009 Kovid Goyal <kovid at kovidgoyal.net>
-// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag at alfa.de>
-// Copyright (C) 2013, 2018 Albert Astals Cid <aacid at kde.org>
-// Copyright (C) 2013 Adam Reichold <adamreichold at myopera.com>
-// Copyright (C) 2014 Bogdan Cristea <cristeab at gmail.com>
-// Copyright (C) 2014 Peter Breitenlohner <peb at mppmu.mpg.de>
-// Copyright (C) 2017 Adrian Johnson <ajohnson at redneon.com>
-//
-// To see a description of the changes please see the Changelog file that
-// came with your tarball or type make ChangeLog if you are building from git
-//
-//========================================================================
-
-#ifndef GMUTEX_H
-#define GMUTEX_H
-
-#ifdef MULTITHREADED
-
-// Usage:
-//
-// GooMutex m;
-// gInitMutex(&m);
-// ...
-// gLockMutex(&m);
-//   ... critical section ...
-// gUnlockMutex(&m);
-// ...
-// gDestroyMutex(&m);
-
-#ifdef _WIN32
-#ifndef NOMINMAX
-#define NOMINMAX
-#endif
-#include <windows.h>
-
-typedef CRITICAL_SECTION GooMutex;
-
-#define gInitMutex(m) InitializeCriticalSection(m)
-#define gDestroyMutex(m) DeleteCriticalSection(m)
-#define gLockMutex(m) EnterCriticalSection(m)
-#define gUnlockMutex(m) LeaveCriticalSection(m)
-
-#else // assume pthreads
-
-#include <pthread.h>
-
-typedef pthread_mutex_t GooMutex;
-
-inline void gInitMutex(GooMutex *m) {
-  pthread_mutexattr_t mutexattr;
-  pthread_mutexattr_init(&mutexattr);
-  pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
-  pthread_mutex_init(m, &mutexattr);
-  pthread_mutexattr_destroy(&mutexattr);
-}
-#define gDestroyMutex(m) pthread_mutex_destroy(m)
-#define gLockMutex(m) pthread_mutex_lock(m)
-#define gUnlockMutex(m) pthread_mutex_unlock(m)
-
-#endif
-
-class MutexLocker {
-public:
-  MutexLocker(GooMutex *mutexA) : mutex(mutexA) { gLockMutex(mutex); }
-  ~MutexLocker() { gUnlockMutex(mutex); }
-
-  MutexLocker(const MutexLocker &) = delete;
-  MutexLocker& operator=(const MutexLocker &other) = delete;
-
-private:
-  GooMutex *mutex;
-};
-
-#endif // MULTITHREADED
-
-#endif // GMUTEX_H
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 61870bd5..392aa5ba 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -83,11 +83,9 @@
 #include <algorithm>
 
 #ifdef MULTITHREADED
-#  define annotLocker()   MutexLocker locker(&mutex)
-#  define annotCondLocker(X)  MutexLocker locker(&mutex, (X))
+#  define annotLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
 #else
 #  define annotLocker()
-#  define annotCondLocker(X)
 #endif
 
 #define fieldFlagReadOnly           0x00000001
@@ -1399,10 +1397,6 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) {
   }
 
   oc = dict->lookupNF("OC");
-
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
 }
 
 void Annot::getRect(double *x1, double *y1, double *x2, double *y2) const {
@@ -1634,24 +1628,13 @@ void Annot::removeReferencedObjects() {
 }
 
 void Annot::incRefCnt() {
-  annotLocker();
   refCnt++;
 }
 
 void Annot::decRefCnt() {
-#ifdef MULTITHREADED
-  gLockMutex(&mutex);
-#endif
   if (--refCnt == 0) {
-#ifdef MULTITHREADED
-    gUnlockMutex(&mutex);
-#endif
     delete this;
-    return;
   }
-#ifdef MULTITHREADED
-  gUnlockMutex(&mutex);
-#endif
 }
 
 Annot::~Annot() {
@@ -1675,10 +1658,6 @@ Annot::~Annot() {
 
   if (color)
     delete color;
-
-#ifdef MULTITHREADED
-    gDestroyMutex(&mutex);
-#endif
 }
 
 void AnnotAppearanceBuilder::setDrawColor(const AnnotColor *drawColor, GBool fill) {
diff --git a/poppler/Annot.h b/poppler/Annot.h
index d564c413..33c2b65c 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -43,6 +43,9 @@
 #endif
 
 #include <memory>
+#include <atomic>
+#include <mutex>
+
 #include "Object.h"
 
 class XRef;
@@ -738,7 +741,7 @@ protected:
 
   Object annotObj;
 
-  int refCnt;
+  std::atomic_int refCnt;
   
   // required data
   AnnotSubtype type;                // Annotation type
@@ -767,7 +770,7 @@ protected:
 
   bool hasRef;
 #ifdef MULTITHREADED
-  GooMutex mutex;
+  mutable std::recursive_mutex mutex;
 #endif
 };
 
diff --git a/poppler/Array.cc b/poppler/Array.cc
index f2dc2363..c6df8581 100644
--- a/poppler/Array.cc
+++ b/poppler/Array.cc
@@ -39,7 +39,7 @@
 #include "Array.h"
 
 #ifdef MULTITHREADED
-#  define arrayLocker()   MutexLocker locker(&mutex)
+#  define arrayLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
 #else
 #  define arrayLocker()
 #endif
@@ -52,9 +52,6 @@ Array::Array(XRef *xrefA) {
   elems = nullptr;
   size = length = 0;
   ref = 1;
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
 }
 
 Array::~Array() {
@@ -63,9 +60,6 @@ Array::~Array() {
   for (i = 0; i < length; ++i)
     elems[i].free();
   gfree(elems);
-#ifdef MULTITHREADED
-  gDestroyMutex(&mutex);
-#endif
 }
 
 Object Array::copy(XRef *xrefA) const {
@@ -77,18 +71,6 @@ Object Array::copy(XRef *xrefA) const {
   return Object(a);
 }
 
-int Array::incRef() {
-  arrayLocker();
-  ++ref;
-  return ref;
-}
-
-int Array::decRef() {
-  arrayLocker();
-  --ref;
-  return ref;
-}
-
 void Array::add(Object &&elem) {
   arrayLocker();
   if (length == size) {
diff --git a/poppler/Array.h b/poppler/Array.h
index cd71c825..d7ba1851 100644
--- a/poppler/Array.h
+++ b/poppler/Array.h
@@ -31,9 +31,11 @@
 #pragma interface
 #endif
 
+#include <atomic>
+#include <mutex>
+
 #include "poppler-config.h"
 #include "Object.h"
-#include "goo/GooMutex.h"
 
 class XRef;
 
@@ -75,16 +77,16 @@ private:
   friend class Object; // for incRef/decRef
 
   // Reference counting.
-  int incRef();
-  int decRef();
+  int incRef() { return ++ref; }
+  int decRef() { return --ref; }
 
   XRef *xref;			// the xref table for this PDF file
   Object *elems;		// array of elements
   int size;			// size of <elems> array
   int length;			// number of elements in array
-  int ref;			// reference count
+  std::atomic_int ref;			// reference count
 #ifdef MULTITHREADED
-  mutable GooMutex mutex;
+  mutable std::recursive_mutex mutex;
 #endif
 };
 
diff --git a/poppler/CMap.cc b/poppler/CMap.cc
index 614009b7..f38b3c73 100644
--- a/poppler/CMap.cc
+++ b/poppler/CMap.cc
@@ -313,9 +313,6 @@ CMap::CMap(GooString *collectionA, GooString *cMapNameA) {
     vector[i].cid = 0;
   }
   refCnt = 1;
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
 }
 
 CMap::CMap(GooString *collectionA, GooString *cMapNameA, int wModeA) {
@@ -325,9 +322,6 @@ CMap::CMap(GooString *collectionA, GooString *cMapNameA, int wModeA) {
   wMode = wModeA;
   vector = nullptr;
   refCnt = 1;
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
 }
 
 void CMap::useCMap(CMapCache *cache, char *useName) {
@@ -433,9 +427,6 @@ CMap::~CMap() {
   if (vector) {
     freeCMapVector(vector);
   }
-#ifdef MULTITHREADED
-  gDestroyMutex(&mutex);
-#endif
 }
 
 void CMap::freeCMapVector(CMapVectorEntry *vec) {
@@ -450,26 +441,11 @@ void CMap::freeCMapVector(CMapVectorEntry *vec) {
 }
 
 void CMap::incRefCnt() {
-#ifdef MULTITHREADED
-  gLockMutex(&mutex);
-#endif
   ++refCnt;
-#ifdef MULTITHREADED
-  gUnlockMutex(&mutex);
-#endif
 }
 
 void CMap::decRefCnt() {
-  GBool done;
-
-#ifdef MULTITHREADED
-  gLockMutex(&mutex);
-#endif
-  done = --refCnt == 0;
-#ifdef MULTITHREADED
-  gUnlockMutex(&mutex);
-#endif
-  if (done) {
+  if (--refCnt == 0) {
     delete this;
   }
 }
diff --git a/poppler/CMap.h b/poppler/CMap.h
index eb9893ac..f2f09c99 100644
--- a/poppler/CMap.h
+++ b/poppler/CMap.h
@@ -29,14 +29,12 @@
 #pragma interface
 #endif
 
+#include <atomic>
+
 #include "poppler-config.h"
 #include "goo/gtypes.h"
 #include "CharTypes.h"
 
-#ifdef MULTITHREADED
-#include "goo/GooMutex.h"
-#endif
-
 class GooString;
 class Object;
 struct CMapVectorEntry;
@@ -116,10 +114,7 @@ private:
   int wMode;			// writing mode (0=horizontal, 1=vertical)
   CMapVectorEntry *vector;	// vector for first byte (NULL for
 				//   identity CMap)
-  int refCnt;
-#ifdef MULTITHREADED
-  GooMutex mutex;
-#endif
+  std::atomic_int refCnt;
 };
 
 //------------------------------------------------------------------------
diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
index 91deac46..b95348bf 100644
--- a/poppler/CairoFontEngine.cc
+++ b/poppler/CairoFontEngine.cc
@@ -61,7 +61,7 @@
 #endif
 
 #ifdef MULTITHREADED
-#  define fontEngineLocker()   MutexLocker locker(&mutex)
+#  define fontEngineLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
 #else
 #  define fontEngineLocker()
 #endif
@@ -815,9 +815,6 @@ CairoFontEngine::CairoFontEngine(FT_Library libA) {
   FT_Library_Version(lib, &major, &minor, &patch);
   useCIDs = major > 2 ||
             (major == 2 && (minor > 1 || (minor == 1 && patch > 7)));
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
 }
 
 CairoFontEngine::~CairoFontEngine() {
@@ -827,9 +824,6 @@ CairoFontEngine::~CairoFontEngine() {
     if (fontCache[i])
       delete fontCache[i];
   }
-#ifdef MULTITHREADED
-  gDestroyMutex(&mutex);
-#endif
 }
 
 CairoFont *
diff --git a/poppler/CairoFontEngine.h b/poppler/CairoFontEngine.h
index 601fbae8..909e2224 100644
--- a/poppler/CairoFontEngine.h
+++ b/poppler/CairoFontEngine.h
@@ -33,6 +33,8 @@
 #pragma interface
 #endif
 
+#include <mutex>
+
 #include "poppler-config.h"
 #include "goo/gtypes.h"
 #include <cairo-ft.h>
@@ -126,7 +128,7 @@ private:
   FT_Library lib;
   GBool useCIDs;
 #ifdef MULTITHREADED
-  GooMutex mutex;
+  mutable std::recursive_mutex mutex;
 #endif
 };
 
diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc
index 55b7528b..df692fd6 100644
--- a/poppler/Catalog.cc
+++ b/poppler/Catalog.cc
@@ -67,7 +67,7 @@
 #include "StructTreeRoot.h"
 
 #ifdef MULTITHREADED
-#  define catalogLocker()   MutexLocker locker(&mutex)
+#  define catalogLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
 #else
 #  define catalogLocker()
 #endif
@@ -76,9 +76,6 @@
 //------------------------------------------------------------------------
 
 Catalog::Catalog(PDFDoc *docA) {
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
   ok = gTrue;
   doc = docA;
   xref = doc->getXRef();
@@ -171,9 +168,6 @@ Catalog::~Catalog() {
   delete optContent;
   delete viewerPrefs;
   delete structTreeRoot;
-#ifdef MULTITHREADED
-  gDestroyMutex(&mutex);
-#endif
 }
 
 GooString *Catalog::readMetadata() {
diff --git a/poppler/Catalog.h b/poppler/Catalog.h
index 5c8c5070..869d16cf 100644
--- a/poppler/Catalog.h
+++ b/poppler/Catalog.h
@@ -43,7 +43,6 @@
 
 #include "poppler-config.h"
 #include "Object.h"
-#include "goo/GooMutex.h"
 
 #include <vector>
 
@@ -293,7 +292,7 @@ private:
   NameTree *getJSNameTree();
   LinkDest *createLinkDest(Object *obj);
 #ifdef MULTITHREADED
-  GooMutex mutex;
+  mutable std::recursive_mutex mutex;
 #endif
 
 };
diff --git a/poppler/CharCodeToUnicode.cc b/poppler/CharCodeToUnicode.cc
index fed6cdb7..c40ee48f 100644
--- a/poppler/CharCodeToUnicode.cc
+++ b/poppler/CharCodeToUnicode.cc
@@ -488,9 +488,6 @@ CharCodeToUnicode::CharCodeToUnicode() {
   sMapLen = sMapSize = 0;
   refCnt = 1;
   isIdentity = gFalse;
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
 }
 
 CharCodeToUnicode::CharCodeToUnicode(GooString *tagA) {
@@ -506,9 +503,6 @@ CharCodeToUnicode::CharCodeToUnicode(GooString *tagA) {
   sMapLen = sMapSize = 0;
   refCnt = 1;
   isIdentity = gFalse;
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
 }
 
 CharCodeToUnicode::CharCodeToUnicode(GooString *tagA, Unicode *mapA,
@@ -528,9 +522,6 @@ CharCodeToUnicode::CharCodeToUnicode(GooString *tagA, Unicode *mapA,
   sMapSize = sMapSizeA;
   refCnt = 1;
   isIdentity = gFalse;
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
 }
 
 CharCodeToUnicode::~CharCodeToUnicode() {
@@ -542,32 +533,14 @@ CharCodeToUnicode::~CharCodeToUnicode() {
     for (int i = 0; i < sMapLen; ++i) gfree(sMap[i].u);
     gfree(sMap);
   }
-#ifdef MULTITHREADED
-  gDestroyMutex(&mutex);
-#endif
 }
 
 void CharCodeToUnicode::incRefCnt() {
-#ifdef MULTITHREADED
-  gLockMutex(&mutex);
-#endif
   ++refCnt;
-#ifdef MULTITHREADED
-  gUnlockMutex(&mutex);
-#endif
 }
 
 void CharCodeToUnicode::decRefCnt() {
-  GBool done;
-
-#ifdef MULTITHREADED
-  gLockMutex(&mutex);
-#endif
-  done = --refCnt == 0;
-#ifdef MULTITHREADED
-  gUnlockMutex(&mutex);
-#endif
-  if (done) {
+  if (--refCnt == 0) {
     delete this;
   }
 }
diff --git a/poppler/CharCodeToUnicode.h b/poppler/CharCodeToUnicode.h
index 5a10fa24..e726176f 100644
--- a/poppler/CharCodeToUnicode.h
+++ b/poppler/CharCodeToUnicode.h
@@ -34,14 +34,12 @@
 #pragma interface
 #endif
 
+#include <atomic>
+
 #include "poppler-config.h"
 #include "CharTypes.h"
 #include "goo/gtypes.h"
 
-#ifdef MULTITHREADED
-#include "goo/GooMutex.h"
-#endif
-
 struct CharCodeToUnicodeString;
 class GooString;
 
@@ -120,11 +118,8 @@ private:
   CharCode mapLen;
   CharCodeToUnicodeString *sMap;
   int sMapLen, sMapSize;
-  int refCnt;
+  std::atomic_int refCnt;
   GBool isIdentity;
-#ifdef MULTITHREADED
-  GooMutex mutex;
-#endif
 };
 
 //------------------------------------------------------------------------
diff --git a/poppler/Dict.cc b/poppler/Dict.cc
index 0a0ceab3..2e013c78 100644
--- a/poppler/Dict.cc
+++ b/poppler/Dict.cc
@@ -41,7 +41,7 @@
 #include "Dict.h"
 
 #ifdef MULTITHREADED
-#  define dictLocker()   MutexLocker locker(&mutex)
+#  define dictLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
 #else
 #  define dictLocker()
 #endif
@@ -66,9 +66,6 @@ struct Dict::CmpDictEntry {
 Dict::Dict(XRef *xrefA) {
   xref = xrefA;
   ref = 1;
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
 
   sorted = false;
 }
@@ -76,9 +73,6 @@ Dict::Dict(XRef *xrefA) {
 Dict::Dict(const Dict* dictA) {
   xref = dictA->xref;
   ref = 1;
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
 
   entries.reserve(dictA->entries.size());
   for (const auto& entry : dictA->entries) {
@@ -100,12 +94,6 @@ Dict *Dict::copy(XRef *xrefA) const {
   return dictA;
 }
 
-Dict::~Dict() {
-#ifdef MULTITHREADED
-  gDestroyMutex(&mutex);
-#endif
-}
-
 void Dict::add(const char *key, Object &&val) {
   dictLocker();
   entries.emplace_back(key, std::move(val));
diff --git a/poppler/Dict.h b/poppler/Dict.h
index a4fd1c56..8271c830 100644
--- a/poppler/Dict.h
+++ b/poppler/Dict.h
@@ -35,13 +35,13 @@
 #endif
 
 #include <atomic>
+#include <mutex>
 #include <string>
 #include <vector>
 #include <utility>
 
 #include "poppler-config.h"
 #include "Object.h"
-#include "goo/GooMutex.h"
 
 //------------------------------------------------------------------------
 // Dict
@@ -55,9 +55,6 @@ public:
   Dict(const Dict *dictA);
   Dict *copy(XRef *xrefA) const;
 
-  // Destructor.
-  ~Dict();
-
   Dict(const Dict &) = delete;
   Dict& operator=(const Dict &) = delete;
 
@@ -115,7 +112,7 @@ private:
   std::vector<DictEntry> entries;
   std::atomic_int ref;			// reference count
 #ifdef MULTITHREADED
-  mutable GooMutex mutex;
+  mutable std::recursive_mutex mutex;
 #endif
 
   const DictEntry *find(const char *key) const;
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index c1131df3..410b3965 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -93,12 +93,12 @@
 #endif
 
 #ifdef MULTITHREADED
-#  define lockGlobalParams            gLockMutex(&mutex)
-#  define lockUnicodeMapCache         gLockMutex(&unicodeMapCacheMutex)
-#  define lockCMapCache               gLockMutex(&cMapCacheMutex)
-#  define unlockGlobalParams          gUnlockMutex(&mutex)
-#  define unlockUnicodeMapCache       gUnlockMutex(&unicodeMapCacheMutex)
-#  define unlockCMapCache             gUnlockMutex(&cMapCacheMutex)
+#  define lockGlobalParams            mutex.lock()
+#  define lockUnicodeMapCache         unicodeMapCacheMutex.lock()
+#  define lockCMapCache               cMapCacheMutex.lock()
+#  define unlockGlobalParams          mutex.unlock()
+#  define unlockUnicodeMapCache       unicodeMapCacheMutex.unlock()
+#  define unlockCMapCache             cMapCacheMutex.unlock()
 #else
 #  define lockGlobalParams
 #  define lockUnicodeMapCache
@@ -550,12 +550,6 @@ Plugin::~Plugin() {
 GlobalParams::GlobalParams(const char *customPopplerDataDir)
   : popplerDataDir(customPopplerDataDir)
 {
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-  gInitMutex(&unicodeMapCacheMutex);
-  gInitMutex(&cMapCacheMutex);
-#endif
-
   initBuiltinFontTables();
 
   // scan the encoding in reverse because we want the lowest-numbered
@@ -747,12 +741,6 @@ GlobalParams::~GlobalParams() {
   delete securityHandlers;
   deleteGooList(plugins, Plugin);
 #endif
-
-#ifdef MULTITHREADED
-  gDestroyMutex(&mutex);
-  gDestroyMutex(&unicodeMapCacheMutex);
-  gDestroyMutex(&cMapCacheMutex);
-#endif
 }
 
 //------------------------------------------------------------------------
diff --git a/poppler/GlobalParams.h b/poppler/GlobalParams.h
index 37124f6b..4c21ba39 100644
--- a/poppler/GlobalParams.h
+++ b/poppler/GlobalParams.h
@@ -48,10 +48,7 @@
 #include "UnicodeMap.h"
 #include <unordered_map>
 #include <string>
-
-#ifdef MULTITHREADED
-#include "goo/GooMutex.h"
-#endif
+#include <mutex>
 
 class GooString;
 class GooList;
@@ -246,9 +243,9 @@ private:
 #endif
 
 #ifdef MULTITHREADED
-  GooMutex mutex;
-  GooMutex unicodeMapCacheMutex;
-  GooMutex cMapCacheMutex;
+  mutable std::recursive_mutex mutex;
+  mutable std::recursive_mutex unicodeMapCacheMutex;
+  mutable std::recursive_mutex cMapCacheMutex;
 #endif
 
   const char *popplerDataDir;
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index cb8fd0d7..d8b39a75 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -92,7 +92,7 @@
 #include "UTF.h"
 
 #ifdef MULTITHREADED
-#  define pdfdocLocker()   MutexLocker locker(&mutex)
+#  define pdfdocLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
 #else
 #  define pdfdocLocker()
 #endif
@@ -116,9 +116,6 @@
 
 void PDFDoc::init()
 {
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
   ok = gFalse;
   errCode = errNone;
   fileName = nullptr;
@@ -368,9 +365,6 @@ PDFDoc::~PDFDoc() {
     gfree(fileNameU);
   }
 #endif
-#ifdef MULTITHREADED
-  gDestroyMutex(&mutex);
-#endif
 }
 
 
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index 3353db74..1017eaca 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -45,9 +45,10 @@
 #pragma interface
 #endif
 
+#include <mutex>
+
 #include "poppler-config.h"
 #include <stdio.h>
-#include "goo/GooMutex.h"
 #include "XRef.h"
 #include "Catalog.h"
 #include "Page.h"
@@ -433,7 +434,7 @@ private:
 
   Goffset startXRefPos;		// offset of last xref table
 #ifdef MULTITHREADED
-  GooMutex mutex;
+  mutable std::recursive_mutex mutex;
 #endif
 };
 
diff --git a/poppler/Page.cc b/poppler/Page.cc
index d4799dd1..ce69c582 100644
--- a/poppler/Page.cc
+++ b/poppler/Page.cc
@@ -62,7 +62,7 @@
 #include "Form.h"
 
 #ifdef MULTITHREADED
-#  define pageLocker()   MutexLocker locker(&mutex)
+#  define pageLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
 #else
 #  define pageLocker()
 #endif
@@ -249,9 +249,6 @@ GBool PageAttrs::readBox(Dict *dict, const char *key, PDFRectangle *box) {
 //------------------------------------------------------------------------
 
 Page::Page(PDFDoc *docA, int numA, Object *pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form) {
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
   ok = gTrue;
   doc = docA;
   xref = doc->getXRef();
@@ -328,9 +325,6 @@ Page::Page(PDFDoc *docA, int numA, Object *pageDict, Ref pageRefA, PageAttrs *at
 Page::~Page() {
   delete attrs;
   delete annots;
-#ifdef MULTITHREADED
-  gDestroyMutex(&mutex);
-#endif
 }
 
 Dict *Page::getResourceDict() { 
diff --git a/poppler/Page.h b/poppler/Page.h
index 7151ee5b..2d565e5d 100644
--- a/poppler/Page.h
+++ b/poppler/Page.h
@@ -36,9 +36,10 @@
 #pragma interface
 #endif
 
+#include <mutex>
+
 #include "poppler-config.h"
 #include "Object.h"
-#include "goo/GooMutex.h"
 
 class Dict;
 class PDFDoc;
@@ -286,7 +287,7 @@ private:
   double duration;              // page duration
   GBool ok;			// true if page is valid
 #ifdef MULTITHREADED
-  GooMutex mutex;
+  mutable std::recursive_mutex mutex;
 #endif
 };
 
diff --git a/poppler/Stream.cc b/poppler/Stream.cc
index 2c55f295..05c1530d 100644
--- a/poppler/Stream.cc
+++ b/poppler/Stream.cc
@@ -94,39 +94,15 @@ static GBool setDJSYSFLAGS = gFalse;
 #endif
 #endif
 
-#ifdef MULTITHREADED
-#  define streamLocker()   MutexLocker locker(&mutex)
-#else
-#  define streamLocker()
-#endif
 //------------------------------------------------------------------------
 // Stream (base class)
 //------------------------------------------------------------------------
 
 Stream::Stream() {
   ref = 1;
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
 }
 
-Stream::~Stream() {
-#ifdef MULTITHREADED
-  gDestroyMutex(&mutex);
-#endif
-}
-
-int Stream::incRef() {
-  streamLocker();
-  ++ref;
-  return ref;
-}
-
-int Stream::decRef() {
-  streamLocker();
-  --ref;
-  return ref;
-}
+Stream::~Stream() = default;
 
 void Stream::close() {
 }
diff --git a/poppler/Stream.h b/poppler/Stream.h
index 841c87a8..0b78f87a 100644
--- a/poppler/Stream.h
+++ b/poppler/Stream.h
@@ -39,11 +39,12 @@
 #pragma interface
 #endif
 
+#include <atomic>
+#include <cstdio>
+
 #include "poppler-config.h"
-#include <stdio.h>
 #include "goo/gtypes.h"
 #include "Object.h"
-#include "goo/GooMutex.h"
 
 class GooFile;
 class BaseStream;
@@ -232,18 +233,15 @@ private:
   friend class Object; // for incRef/decRef
 
   // Reference counting.
-  int incRef();
-  int decRef();
+  int incRef() { return ++ref; }
+  int decRef() { return --ref; }
 
   virtual GBool hasGetChars() { return false; }
   virtual int getChars(int nChars, Guchar *buffer);
 
   Stream *makeFilter(const char *name, Stream *str, Object *params, int recursion = 0, Dict *dict = nullptr);
 
-  int ref;			// reference count
-#ifdef MULTITHREADED
-  GooMutex mutex;
-#endif
+  std::atomic_int ref;			// reference count
 };
 
 
diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index 078274b4..18e3d337 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -73,11 +73,9 @@
 #define defPermFlags 0xfffc
 
 #ifdef MULTITHREADED
-#  define xrefLocker()   MutexLocker locker(&mutex)
-#  define xrefCondLocker(X)  MutexLocker locker(&mutex, (X))
+#  define xrefLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
 #else
 #  define xrefLocker()
-#  define xrefCondLocker(X)
 #endif
 
 //------------------------------------------------------------------------
@@ -265,9 +263,6 @@ Object ObjectStream::getObject(int objIdx, int objNum) {
 //------------------------------------------------------------------------
 
 void XRef::init() {
-#ifdef MULTITHREADED
-  gInitMutex(&mutex);
-#endif
   ok = gTrue;
   errCode = errNone;
   entries = nullptr;
@@ -388,9 +383,6 @@ XRef::~XRef() {
   if (strOwner) {
     delete str;
   }
-#ifdef MULTITHREADED
-  gDestroyMutex(&mutex);
-#endif
 }
 
 XRef *XRef::copy() const {
@@ -1242,13 +1234,13 @@ Object XRef::fetch(int num, int gen, int recursion) {
 
 void XRef::lock() {
 #ifdef MULTITHREADED
-  gLockMutex(&mutex);
+  mutex.lock();
 #endif
 }
 
 void XRef::unlock() {
 #ifdef MULTITHREADED
-  gUnlockMutex(&mutex);
+  mutex.unlock();
 #endif
 }
 
diff --git a/poppler/XRef.h b/poppler/XRef.h
index bf904d50..68c507ac 100644
--- a/poppler/XRef.h
+++ b/poppler/XRef.h
@@ -38,7 +38,6 @@
 
 #include "poppler-config.h"
 #include "goo/gtypes.h"
-#include "goo/GooMutex.h"
 #include "Object.h"
 #include "Stream.h"
 
@@ -239,7 +238,7 @@ private:
   GBool scannedSpecialFlags;	// true if scanSpecialFlags has been called
   GBool strOwner;     // true if str is owned by the instance
 #ifdef MULTITHREADED
-  GooMutex mutex;
+  mutable std::recursive_mutex mutex;
 #endif
 
   void init();


More information about the poppler mailing list