Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 57cdd6b

Browse files
committed
Ensure the collator map is thread safe on SortHandle.
1 parent a99bf5f commit 57cdd6b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/corefx/System.Globalization.Native/collation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//
66

77
#include <assert.h>
8+
#include <pthread.h>
89
#include <stdint.h>
910
#include <vector>
1011
#include <map>
@@ -32,9 +33,11 @@ typedef struct _sort_handle
3233
{
3334
UCollator* regular;
3435
TCollatorMap collatorsPerOption;
36+
pthread_mutex_t collatorsLockObject;
3537

3638
_sort_handle() : regular(nullptr)
3739
{
40+
pthread_mutex_init(&collatorsLockObject, NULL);
3841
}
3942

4043
} SortHandle;
@@ -272,6 +275,8 @@ extern "C" void CloseSortHandle(SortHandle* pSortHandle)
272275
ucol_close(it->second);
273276
}
274277

278+
pthread_mutex_destroy(&pSortHandle->collatorsLockObject);
279+
275280
delete pSortHandle;
276281
}
277282

@@ -284,6 +289,8 @@ const UCollator* GetCollatorFromSortHandle(SortHandle* pSortHandle, int32_t opti
284289
}
285290
else
286291
{
292+
pthread_mutex_lock(&pSortHandle->collatorsLockObject);
293+
287294
TCollatorMap::iterator entry = pSortHandle->collatorsPerOption.find(options);
288295
if (entry == pSortHandle->collatorsPerOption.end())
289296
{
@@ -294,6 +301,8 @@ const UCollator* GetCollatorFromSortHandle(SortHandle* pSortHandle, int32_t opti
294301
{
295302
pCollator = entry->second;
296303
}
304+
305+
pthread_mutex_unlock(&pSortHandle->collatorsLockObject);
297306
}
298307

299308
return pCollator;

0 commit comments

Comments
 (0)