summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qunicodetools.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/text/qunicodetools.cpp')
-rw-r--r--src/corelib/text/qunicodetools.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/corelib/text/qunicodetools.cpp b/src/corelib/text/qunicodetools.cpp
index a2a080d4ae..9d6590c6b8 100644
--- a/src/corelib/text/qunicodetools.cpp
+++ b/src/corelib/text/qunicodetools.cpp
@@ -3,12 +3,15 @@
#include "qunicodetools_p.h"
+#include "qmutex.h"
#include "qunicodetables_p.h"
#include "qvarlengtharray.h"
#if QT_CONFIG(library)
#include "qlibrary.h"
#endif
+#include <mutex>
+
#include <limits.h>
#define FLAG(x) (1 << (x))
@@ -1405,11 +1408,15 @@ Q_CONSTINIT static th_next_cell_def th_next_cell = nullptr;
static int init_libthai() {
#if QT_CONFIG(library)
- Q_CONSTINIT static bool initialized = false;
- if (!initialized && (!th_brk || !th_next_cell)) {
- th_brk = reinterpret_cast<th_brk_def>(QLibrary::resolve("thai"_L1, static_cast<int>(LIBTHAI_MAJOR), "th_brk"));
- th_next_cell = (th_next_cell_def)QLibrary::resolve("thai"_L1, LIBTHAI_MAJOR, "th_next_cell");
- initialized = true;
+ Q_CONSTINIT static QBasicAtomicInt initialized = Q_BASIC_ATOMIC_INITIALIZER(false);
+ Q_CONSTINIT static QBasicMutex mutex;
+ if (!initialized.loadAcquire()) {
+ const auto locker = std::scoped_lock(mutex);
+ if (!initialized.loadAcquire()) {
+ th_brk = reinterpret_cast<th_brk_def>(QLibrary::resolve("thai"_L1, LIBTHAI_MAJOR, "th_brk"));
+ th_next_cell = (th_next_cell_def)QLibrary::resolve("thai"_L1, LIBTHAI_MAJOR, "th_next_cell");
+ initialized.storeRelease(true);
+ }
}
if (th_brk && th_next_cell)
return 1;