Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pdf/xpdf/UnicodeMap.cc
diff options
context:
space:
mode:
Diffstat (limited to 'pdf/xpdf/UnicodeMap.cc')
-rw-r--r--pdf/xpdf/UnicodeMap.cc70
1 files changed, 48 insertions, 22 deletions
diff --git a/pdf/xpdf/UnicodeMap.cc b/pdf/xpdf/UnicodeMap.cc
index e6284eb..300d802 100644
--- a/pdf/xpdf/UnicodeMap.cc
+++ b/pdf/xpdf/UnicodeMap.cc
@@ -116,6 +116,9 @@ UnicodeMap::UnicodeMap(GString *encodingNameA) {
eMaps = NULL;
eMapsLen = 0;
refCnt = 1;
+#if MULTITHREADED
+ gInitMutex(&mutex);
+#endif
}
UnicodeMap::UnicodeMap(char *encodingNameA, GBool unicodeOutA,
@@ -128,6 +131,9 @@ UnicodeMap::UnicodeMap(char *encodingNameA, GBool unicodeOutA,
eMaps = NULL;
eMapsLen = 0;
refCnt = 1;
+#if MULTITHREADED
+ gInitMutex(&mutex);
+#endif
}
UnicodeMap::UnicodeMap(char *encodingNameA, GBool unicodeOutA,
@@ -139,6 +145,9 @@ UnicodeMap::UnicodeMap(char *encodingNameA, GBool unicodeOutA,
eMaps = NULL;
eMapsLen = 0;
refCnt = 1;
+#if MULTITHREADED
+ gInitMutex(&mutex);
+#endif
}
UnicodeMap::~UnicodeMap() {
@@ -149,14 +158,32 @@ UnicodeMap::~UnicodeMap() {
if (eMaps) {
gfree(eMaps);
}
+#if MULTITHREADED
+ gDestroyMutex(&mutex);
+#endif
}
void UnicodeMap::incRefCnt() {
+#if MULTITHREADED
+ gLockMutex(&mutex);
+#endif
++refCnt;
+#if MULTITHREADED
+ gUnlockMutex(&mutex);
+#endif
}
void UnicodeMap::decRefCnt() {
- if (--refCnt == 0) {
+ GBool done;
+
+#if MULTITHREADED
+ gLockMutex(&mutex);
+#endif
+ done = --refCnt == 0;
+#if MULTITHREADED
+ gUnlockMutex(&mutex);
+#endif
+ if (done) {
delete this;
}
}
@@ -175,29 +202,28 @@ int UnicodeMap::mapUnicode(Unicode u, char *buf, int bufSize) {
a = 0;
b = len;
- if (u < ranges[a].start) {
- return 0;
- }
- // invariant: ranges[a].start <= u < ranges[b].start
- while (b - a > 1) {
- m = (a + b) / 2;
- if (u >= ranges[m].start) {
- a = m;
- } else if (u < ranges[m].start) {
- b = m;
- }
- }
- if (u <= ranges[a].end) {
- n = ranges[a].nBytes;
- if (n > bufSize) {
- return 0;
+ if (u >= ranges[a].start) {
+ // invariant: ranges[a].start <= u < ranges[b].start
+ while (b - a > 1) {
+ m = (a + b) / 2;
+ if (u >= ranges[m].start) {
+ a = m;
+ } else if (u < ranges[m].start) {
+ b = m;
+ }
}
- code = ranges[a].code + (u - ranges[a].start);
- for (i = n - 1; i >= 0; --i) {
- buf[i] = (char)(code & 0xff);
- code >>= 8;
+ if (u <= ranges[a].end) {
+ n = ranges[a].nBytes;
+ if (n > bufSize) {
+ return 0;
+ }
+ code = ranges[a].code + (u - ranges[a].start);
+ for (i = n - 1; i >= 0; --i) {
+ buf[i] = (char)(code & 0xff);
+ code >>= 8;
+ }
+ return n;
}
- return n;
}
for (i = 0; i < eMapsLen; ++i) {