aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/common/umutex.cpp
diff options
context:
space:
mode:
authormcheshkov <mcheshkov@yandex-team.ru>2022-02-10 16:46:16 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:16 +0300
commit1312621288956f199a5bd5342b0133d4395fa725 (patch)
tree1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /contrib/libs/icu/common/umutex.cpp
parente9d19cec64684c9c1e6b0c98297e5b895cf904fe (diff)
downloadydb-1312621288956f199a5bd5342b0133d4395fa725.tar.gz
Restoring authorship annotation for <mcheshkov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/icu/common/umutex.cpp')
-rw-r--r--contrib/libs/icu/common/umutex.cpp176
1 files changed, 88 insertions, 88 deletions
diff --git a/contrib/libs/icu/common/umutex.cpp b/contrib/libs/icu/common/umutex.cpp
index 6a283a15fe..ccbee9960a 100644
--- a/contrib/libs/icu/common/umutex.cpp
+++ b/contrib/libs/icu/common/umutex.cpp
@@ -1,4 +1,4 @@
-// © 2016 and later: Unicode, Inc. and others.
+// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
******************************************************************************
@@ -24,138 +24,138 @@
#include "unicode/utypes.h"
#include "uassert.h"
-#include "ucln_cmn.h"
+#include "ucln_cmn.h"
#include "cmemory.h"
-U_NAMESPACE_BEGIN
+U_NAMESPACE_BEGIN
#if defined(U_USER_MUTEX_CPP)
-// Support for including an alternate implementation of mutexes has been withdrawn.
-// See issue ICU-20185.
-#error U_USER_MUTEX_CPP not supported
+// Support for including an alternate implementation of mutexes has been withdrawn.
+// See issue ICU-20185.
+#error U_USER_MUTEX_CPP not supported
#endif
-/*************************************************************************************************
- *
- * ICU Mutex wrappers.
- *
- *************************************************************************************************/
+/*************************************************************************************************
+ *
+ * ICU Mutex wrappers.
+ *
+ *************************************************************************************************/
-namespace {
-std::mutex *initMutex;
-std::condition_variable *initCondition;
+namespace {
+std::mutex *initMutex;
+std::condition_variable *initCondition;
-// The ICU global mutex.
-// Used when ICU implementation code passes nullptr for the mutex pointer.
-UMutex globalMutex;
+// The ICU global mutex.
+// Used when ICU implementation code passes nullptr for the mutex pointer.
+UMutex globalMutex;
-std::once_flag initFlag;
-std::once_flag *pInitFlag = &initFlag;
+std::once_flag initFlag;
+std::once_flag *pInitFlag = &initFlag;
-} // Anonymous namespace
+} // Anonymous namespace
-U_CDECL_BEGIN
-static UBool U_CALLCONV umtx_cleanup() {
- initMutex->~mutex();
- initCondition->~condition_variable();
- UMutex::cleanup();
+U_CDECL_BEGIN
+static UBool U_CALLCONV umtx_cleanup() {
+ initMutex->~mutex();
+ initCondition->~condition_variable();
+ UMutex::cleanup();
- // Reset the once_flag, by destructing it and creating a fresh one in its place.
- // Do not use this trick anywhere else in ICU; use umtx_initOnce, not std::call_once().
- pInitFlag->~once_flag();
- pInitFlag = new(&initFlag) std::once_flag();
- return true;
+ // Reset the once_flag, by destructing it and creating a fresh one in its place.
+ // Do not use this trick anywhere else in ICU; use umtx_initOnce, not std::call_once().
+ pInitFlag->~once_flag();
+ pInitFlag = new(&initFlag) std::once_flag();
+ return true;
}
-static void U_CALLCONV umtx_init() {
- initMutex = STATIC_NEW(std::mutex);
- initCondition = STATIC_NEW(std::condition_variable);
- ucln_common_registerCleanup(UCLN_COMMON_MUTEX, umtx_cleanup);
+static void U_CALLCONV umtx_init() {
+ initMutex = STATIC_NEW(std::mutex);
+ initCondition = STATIC_NEW(std::condition_variable);
+ ucln_common_registerCleanup(UCLN_COMMON_MUTEX, umtx_cleanup);
}
-U_CDECL_END
-
-
-std::mutex *UMutex::getMutex() {
- std::mutex *retPtr = fMutex.load(std::memory_order_acquire);
- if (retPtr == nullptr) {
- std::call_once(*pInitFlag, umtx_init);
- std::lock_guard<std::mutex> guard(*initMutex);
- retPtr = fMutex.load(std::memory_order_acquire);
- if (retPtr == nullptr) {
- fMutex = new(fStorage) std::mutex();
- retPtr = fMutex;
- fListLink = gListHead;
- gListHead = this;
- }
+U_CDECL_END
+
+
+std::mutex *UMutex::getMutex() {
+ std::mutex *retPtr = fMutex.load(std::memory_order_acquire);
+ if (retPtr == nullptr) {
+ std::call_once(*pInitFlag, umtx_init);
+ std::lock_guard<std::mutex> guard(*initMutex);
+ retPtr = fMutex.load(std::memory_order_acquire);
+ if (retPtr == nullptr) {
+ fMutex = new(fStorage) std::mutex();
+ retPtr = fMutex;
+ fListLink = gListHead;
+ gListHead = this;
+ }
}
- U_ASSERT(retPtr != nullptr);
- return retPtr;
+ U_ASSERT(retPtr != nullptr);
+ return retPtr;
}
-UMutex *UMutex::gListHead = nullptr;
+UMutex *UMutex::gListHead = nullptr;
-void UMutex::cleanup() {
- UMutex *next = nullptr;
- for (UMutex *m = gListHead; m != nullptr; m = next) {
- (*m->fMutex).~mutex();
- m->fMutex = nullptr;
- next = m->fListLink;
- m->fListLink = nullptr;
+void UMutex::cleanup() {
+ UMutex *next = nullptr;
+ for (UMutex *m = gListHead; m != nullptr; m = next) {
+ (*m->fMutex).~mutex();
+ m->fMutex = nullptr;
+ next = m->fListLink;
+ m->fListLink = nullptr;
}
- gListHead = nullptr;
+ gListHead = nullptr;
}
U_CAPI void U_EXPORT2
umtx_lock(UMutex *mutex) {
- if (mutex == nullptr) {
+ if (mutex == nullptr) {
mutex = &globalMutex;
}
- mutex->lock();
+ mutex->lock();
}
U_CAPI void U_EXPORT2
umtx_unlock(UMutex* mutex)
{
- if (mutex == nullptr) {
+ if (mutex == nullptr) {
mutex = &globalMutex;
}
- mutex->unlock();
+ mutex->unlock();
}
-/*************************************************************************************************
- *
- * UInitOnce Implementation
- *
- *************************************************************************************************/
+/*************************************************************************************************
+ *
+ * UInitOnce Implementation
+ *
+ *************************************************************************************************/
// This function is called when a test of a UInitOnce::fState reveals that
-// initialization has not completed, that we either need to call the init
+// initialization has not completed, that we either need to call the init
// function on this thread, or wait for some other thread to complete.
//
// The actual call to the init function is made inline by template code
-// that knows the C++ types involved. This function returns true if
+// that knows the C++ types involved. This function returns true if
// the caller needs to call the Init function.
//
U_COMMON_API UBool U_EXPORT2
umtx_initImplPreInit(UInitOnce &uio) {
- std::call_once(*pInitFlag, umtx_init);
- std::unique_lock<std::mutex> lock(*initMutex);
- if (umtx_loadAcquire(uio.fState) == 0) {
+ std::call_once(*pInitFlag, umtx_init);
+ std::unique_lock<std::mutex> lock(*initMutex);
+ if (umtx_loadAcquire(uio.fState) == 0) {
umtx_storeRelease(uio.fState, 1);
- return true; // Caller will next call the init function.
+ return true; // Caller will next call the init function.
} else {
- while (umtx_loadAcquire(uio.fState) == 1) {
+ while (umtx_loadAcquire(uio.fState) == 1) {
// Another thread is currently running the initialization.
// Wait until it completes.
- initCondition->wait(lock);
+ initCondition->wait(lock);
}
U_ASSERT(uio.fState == 2);
- return false;
+ return false;
}
}
@@ -168,20 +168,20 @@ umtx_initImplPreInit(UInitOnce &uio) {
U_COMMON_API void U_EXPORT2
umtx_initImplPostInit(UInitOnce &uio) {
- {
- std::unique_lock<std::mutex> lock(*initMutex);
- umtx_storeRelease(uio.fState, 2);
- }
- initCondition->notify_all();
+ {
+ std::unique_lock<std::mutex> lock(*initMutex);
+ umtx_storeRelease(uio.fState, 2);
+ }
+ initCondition->notify_all();
}
U_NAMESPACE_END
-/*************************************************************************************************
- *
- * Deprecated functions for setting user mutexes.
- *
- *************************************************************************************************/
+/*************************************************************************************************
+ *
+ * Deprecated functions for setting user mutexes.
+ *
+ *************************************************************************************************/
U_DEPRECATED void U_EXPORT2
u_setMutexFunctions(const void * /*context */, UMtxInitFn *, UMtxFn *,