refactor: use std::mutex in ArchStrings
port b0e415de03
build: link base to arch
This commit is contained in:
committed by
Nick Bolton
parent
fb3c8eb965
commit
f89168d00a
@ -6,28 +6,21 @@
|
||||
*/
|
||||
|
||||
#include "arch/ArchString.h"
|
||||
#include "arch/Arch.h"
|
||||
|
||||
#include <climits>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
|
||||
static ArchMutex s_mutex = nullptr;
|
||||
std::mutex s_mutex;
|
||||
|
||||
//
|
||||
// use C library non-reentrant multibyte conversion with mutex
|
||||
//
|
||||
|
||||
ArchString::~ArchString()
|
||||
{
|
||||
if (s_mutex != nullptr) {
|
||||
ARCH->closeMutex(s_mutex);
|
||||
s_mutex = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int ArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, bool *errors) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_mutex);
|
||||
ptrdiff_t len = 0;
|
||||
|
||||
bool dummyErrors;
|
||||
@ -36,12 +29,6 @@ int ArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, bool
|
||||
}
|
||||
*errors = false;
|
||||
|
||||
if (s_mutex == nullptr) {
|
||||
s_mutex = ARCH->newMutex();
|
||||
}
|
||||
|
||||
ARCH->lockMutex(s_mutex);
|
||||
|
||||
if (dst == nullptr) {
|
||||
char dummy[MB_LEN_MAX];
|
||||
const wchar_t *scan = src;
|
||||
@ -75,7 +62,6 @@ int ArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, bool
|
||||
}
|
||||
len = dst - dst0;
|
||||
}
|
||||
ARCH->unlockMutex(s_mutex);
|
||||
|
||||
return static_cast<int>(len);
|
||||
}
|
||||
@ -91,6 +77,7 @@ ArchString::EWideCharEncoding ArchString::getWideCharEncoding() const
|
||||
|
||||
int ArchString::convStringMBToWC(wchar_t *dst, const char *src, uint32_t n, bool *errors) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_mutex);
|
||||
ptrdiff_t len = 0;
|
||||
wchar_t dummy;
|
||||
|
||||
@ -100,12 +87,6 @@ int ArchString::convStringMBToWC(wchar_t *dst, const char *src, uint32_t n, bool
|
||||
}
|
||||
*errors = false;
|
||||
|
||||
if (s_mutex == nullptr) {
|
||||
s_mutex = ARCH->newMutex();
|
||||
}
|
||||
|
||||
ARCH->lockMutex(s_mutex);
|
||||
|
||||
if (dst == nullptr) {
|
||||
const char *scan = src;
|
||||
while (n > 0) {
|
||||
@ -177,7 +158,6 @@ int ArchString::convStringMBToWC(wchar_t *dst, const char *src, uint32_t n, bool
|
||||
}
|
||||
len = dst - dst0;
|
||||
}
|
||||
ARCH->unlockMutex(s_mutex);
|
||||
|
||||
return static_cast<int>(len);
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ public:
|
||||
ArchString() = default;
|
||||
ArchString(const ArchString &) = delete;
|
||||
ArchString(ArchString &&) = delete;
|
||||
~ArchString() override;
|
||||
~ArchString() = default;
|
||||
|
||||
ArchString &operator=(const ArchString &) = delete;
|
||||
ArchString &operator=(ArchString &&) = delete;
|
||||
|
||||
@ -41,3 +41,4 @@ add_library(base STATIC
|
||||
XBase.h
|
||||
)
|
||||
|
||||
target_link_libraries(base PRIVATE arch)
|
||||
|
||||
Reference in New Issue
Block a user