diff options
| author | 2019-10-05 21:10:12 -0400 | |
|---|---|---|
| committer | 2019-10-05 21:10:12 -0400 | |
| commit | 78fb19eb26c8814cc83c649a252b7f47bdf649a0 (patch) | |
| tree | e8f38f35e404b37d4683604cb2a826ff3f4d2f1d /src/lib/arch/IArchString.cpp | |
| parent | 226b07c35afedc28ad1a769d6bf539e6cab320d4 (diff) | |
| parent | dff8b887edf10407f22aaab9d147948cd5491f0a (diff) | |
Update upstream source from tag 'upstream/2.3.2+dfsg'
Update to upstream version '2.3.2+dfsg'
with Debian dir da6cb58f0203c792df99a475344204697ce64812
Diffstat (limited to 'src/lib/arch/IArchString.cpp')
| -rw-r--r-- | src/lib/arch/IArchString.cpp | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/lib/arch/IArchString.cpp b/src/lib/arch/IArchString.cpp index f618c12..0f7f300 100644 --- a/src/lib/arch/IArchString.cpp +++ b/src/lib/arch/IArchString.cpp @@ -24,7 +24,9 @@ #include <cstring> #include <cstdlib> -static ArchMutex s_mutex = NULL; +#include <mutex> + +std::mutex s_mutex; // // use C library non-reentrant multibyte conversion with mutex @@ -32,16 +34,14 @@ static ArchMutex s_mutex = NULL; IArchString::~IArchString() { - if (s_mutex != NULL) { - ARCH->closeMutex(s_mutex); - s_mutex = NULL; - } } int IArchString::convStringWCToMB(char* dst, const wchar_t* src, UInt32 n, bool* errors) { + std::lock_guard<std::mutex> lock(s_mutex); + ptrdiff_t len = 0; bool dummyErrors; @@ -49,12 +49,6 @@ IArchString::convStringWCToMB(char* dst, errors = &dummyErrors; } - if (s_mutex == NULL) { - s_mutex = ARCH->newMutex(); - } - - ARCH->lockMutex(s_mutex); - if (dst == NULL) { char dummy[MB_LEN_MAX]; for (const wchar_t* scan = src; n > 0; ++scan, --n) { @@ -89,7 +83,6 @@ IArchString::convStringWCToMB(char* dst, } len = dst - dst0; } - ARCH->unlockMutex(s_mutex); return (int)len; } @@ -98,6 +91,8 @@ int IArchString::convStringMBToWC(wchar_t* dst, const char* src, UInt32 n_param, bool* errors) { + std::lock_guard<std::mutex> lock(s_mutex); + ptrdiff_t n = (ptrdiff_t)n_param; // fix compiler warning ptrdiff_t len = 0; wchar_t dummy; @@ -107,12 +102,6 @@ IArchString::convStringMBToWC(wchar_t* dst, errors = &dummyErrors; } - if (s_mutex == NULL) { - s_mutex = ARCH->newMutex(); - } - - ARCH->lockMutex(s_mutex); - if (dst == NULL) { for (const char* scan = src; n > 0; ) { ptrdiff_t mblen = mbtowc(&dummy, scan, n); @@ -184,7 +173,6 @@ IArchString::convStringMBToWC(wchar_t* dst, } len = dst - dst0; } - ARCH->unlockMutex(s_mutex); return (int)len; } |
