summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Erhardt <eric.erhardt@microsoft.com>2015-12-01 00:22:13 -0600
committerEric Erhardt <eric.erhardt@microsoft.com>2015-12-07 09:44:45 -0600
commit9c93cbb1591f129c8989f1273cf4cea24c50aabb (patch)
treea1314523258b58a9aea20ff6c00517fca983997a
parentcc5de3941217a8bb1e22a5e024da0516a39f0619 (diff)
downloadcoreclr-9c93cbb1591f129c8989f1273cf4cea24c50aabb.tar.gz
coreclr-9c93cbb1591f129c8989f1273cf4cea24c50aabb.tar.bz2
coreclr-9c93cbb1591f129c8989f1273cf4cea24c50aabb.zip
Ensure the collator map is thread safe on SortHandle.
-rw-r--r--src/corefx/System.Globalization.Native/collation.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/corefx/System.Globalization.Native/collation.cpp b/src/corefx/System.Globalization.Native/collation.cpp
index f250b63473..240ab8ab08 100644
--- a/src/corefx/System.Globalization.Native/collation.cpp
+++ b/src/corefx/System.Globalization.Native/collation.cpp
@@ -5,6 +5,7 @@
//
#include <assert.h>
+#include <pthread.h>
#include <stdint.h>
#include <vector>
#include <map>
@@ -32,9 +33,11 @@ typedef struct _sort_handle
{
UCollator* regular;
TCollatorMap collatorsPerOption;
+ pthread_mutex_t collatorsLockObject;
_sort_handle() : regular(nullptr)
{
+ pthread_mutex_init(&collatorsLockObject, NULL);
}
} SortHandle;
@@ -272,6 +275,8 @@ extern "C" void CloseSortHandle(SortHandle* pSortHandle)
ucol_close(it->second);
}
+ pthread_mutex_destroy(&pSortHandle->collatorsLockObject);
+
delete pSortHandle;
}
@@ -284,6 +289,8 @@ const UCollator* GetCollatorFromSortHandle(SortHandle* pSortHandle, int32_t opti
}
else
{
+ pthread_mutex_lock(&pSortHandle->collatorsLockObject);
+
TCollatorMap::iterator entry = pSortHandle->collatorsPerOption.find(options);
if (entry == pSortHandle->collatorsPerOption.end())
{
@@ -294,6 +301,8 @@ const UCollator* GetCollatorFromSortHandle(SortHandle* pSortHandle, int32_t opti
{
pCollator = entry->second;
}
+
+ pthread_mutex_unlock(&pSortHandle->collatorsLockObject);
}
return pCollator;