Skip to content

Commit 5a4e960

Browse files
roubertmarkusicu
authored andcommitted
ICU-23221 Bugfix: Use a mutex to lock KnownIssues::fTable.
This will make it safe to access this std::map from parallel threads.
1 parent aaab706 commit 5a4e960

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

icu4c/source/tools/toolutil/udbgutil.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "unicode/ucnv.h"
1717
#include "unicode/unistr.h"
1818
#include "cstr.h"
19+
#include "mutex.h"
20+
#include "umutex.h"
1921

2022
/*
2123
To add a new enum type
@@ -608,6 +610,8 @@ U_CAPI void udbg_writeIcuInfo(FILE *out) {
608610
#include <ostream>
609611
#include <iostream>
610612

613+
static icu::UMutex gKnownIssuesLock;
614+
611615
class KnownIssues {
612616
public:
613617
KnownIssues();
@@ -650,6 +654,7 @@ static std::string mapTicketId(const char *ticketStr) {
650654
void KnownIssues::add(const char *ticketStr, const char *where, const char16_t *msg, UBool *firstForTicket, UBool *firstForWhere)
651655
{
652656
const std::string ticket = mapTicketId(ticketStr);
657+
icu::Mutex mutex(&gKnownIssuesLock);
653658
if(fTable.find(ticket) == fTable.end()) {
654659
if(firstForTicket!=nullptr) *firstForTicket = true;
655660
fTable[ticket] = std::map < std::string, std::set < std::string > >();
@@ -674,6 +679,7 @@ void KnownIssues::add(const char *ticketStr, const char *where, const char16_t *
674679
void KnownIssues::add(const char *ticketStr, const char *where, const char *msg, UBool *firstForTicket, UBool *firstForWhere)
675680
{
676681
const std::string ticket = mapTicketId(ticketStr);
682+
icu::Mutex mutex(&gKnownIssuesLock);
677683
if(fTable.find(ticket) == fTable.end()) {
678684
if(firstForTicket!=nullptr) *firstForTicket = true;
679685
fTable[ticket] = std::map < std::string, std::set < std::string > >();
@@ -696,6 +702,7 @@ void KnownIssues::add(const char *ticketStr, const char *where, const char *msg,
696702

697703
UBool KnownIssues::print()
698704
{
705+
icu::Mutex mutex(&gKnownIssuesLock);
699706
if(fTable.empty()) {
700707
return false;
701708
}

0 commit comments

Comments
 (0)