Created
June 2, 2013 03:27
-
-
Save dinhvh/5692527 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/core/basetypes/MCString.cc b/src/core/basetypes/MCString.cc | |
index 6710e59..2398958 100644 | |
--- a/src/core/basetypes/MCString.cc | |
+++ b/src/core/basetypes/MCString.cc | |
@@ -1975,6 +1975,7 @@ String * String::substringWithRange(Range range) | |
} | |
static chash * uniquedStringHash = NULL; | |
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; | |
static void initUniquedStringHash() | |
{ | |
@@ -1991,14 +1992,17 @@ String * String::uniquedStringWithUTF8Characters(const c | |
har * UTF8Characters) | |
pthread_once(&once, initUniquedStringHash); | |
key.data = (void *) UTF8Characters; | |
key.len = (unsigned int) strlen(UTF8Characters); | |
+ pthread_mutex_lock(&lock); | |
r = chash_get(uniquedStringHash, &key, &value); | |
if (r == 0) { | |
+ pthread_mutex_unlock(&lock); | |
return (String *) value.data; | |
} | |
else { | |
value.data = new String(UTF8Characters); | |
value.len = 0; | |
chash_set(uniquedStringHash, &key, &value, NULL); | |
+ pthread_mutex_unlock(&lock); | |
return (String *) value.data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment