@@ -43,6 +43,7 @@ U_NAMESPACE_BEGIN
4343 *
4444 *************************************************************************************************/
4545
46+ #if U_HAVE_ATOMICS
4647namespace {
4748std::mutex *initMutex;
4849std::condition_variable *initCondition;
@@ -55,9 +56,11 @@ std::once_flag initFlag;
5556std::once_flag *pInitFlag = &initFlag;
5657
5758} // Anonymous namespace
59+ #endif
5860
5961U_CDECL_BEGIN
6062static UBool U_CALLCONV umtx_cleanup () {
63+ #if U_HAVE_ATOMICS
6164 initMutex->~mutex ();
6265 initCondition->~condition_variable ();
6366 UMutex::cleanup ();
@@ -66,17 +69,21 @@ static UBool U_CALLCONV umtx_cleanup() {
6669 // Do not use this trick anywhere else in ICU; use umtx_initOnce, not std::call_once().
6770 pInitFlag->~once_flag ();
6871 pInitFlag = new (&initFlag) std::once_flag ();
72+ #endif
6973 return true ;
7074}
7175
7276static void U_CALLCONV umtx_init () {
77+ #if U_HAVE_ATOMICS
7378 initMutex = STATIC_NEW (std::mutex);
7479 initCondition = STATIC_NEW (std::condition_variable);
7580 ucln_common_registerCleanup (UCLN_COMMON_MUTEX, umtx_cleanup);
81+ #endif
7682}
7783U_CDECL_END
7884
7985
86+ #if U_HAVE_ATOMICS
8087std::mutex *UMutex::getMutex () {
8188 std::mutex *retPtr = fMutex .load (std::memory_order_acquire);
8289 if (retPtr == nullptr ) {
@@ -93,14 +100,17 @@ std::mutex *UMutex::getMutex() {
93100 U_ASSERT (retPtr != nullptr );
94101 return retPtr;
95102}
103+ #endif
96104
97105UMutex *UMutex::gListHead = nullptr ;
98106
99107void UMutex::cleanup () {
100108 UMutex *next = nullptr ;
101109 for (UMutex *m = gListHead ; m != nullptr ; m = next) {
110+ #if U_HAVE_ATOMICS
102111 (*m->fMutex ).~mutex ();
103112 m->fMutex = nullptr ;
113+ #endif
104114 next = m->fListLink ;
105115 m->fListLink = nullptr ;
106116 }
@@ -110,20 +120,24 @@ void UMutex::cleanup() {
110120
111121U_CAPI void U_EXPORT2
112122umtx_lock (UMutex *mutex) {
123+ #if U_HAVE_ATOMICS
113124 if (mutex == nullptr ) {
114125 mutex = &globalMutex;
115126 }
116127 mutex->lock ();
128+ #endif
117129}
118130
119131
120132U_CAPI void U_EXPORT2
121133umtx_unlock (UMutex* mutex)
122134{
135+ #if U_HAVE_ATOMICS
123136 if (mutex == nullptr ) {
124137 mutex = &globalMutex;
125138 }
126139 mutex->unlock ();
140+ #endif
127141}
128142
129143
@@ -143,18 +157,22 @@ umtx_unlock(UMutex* mutex)
143157//
144158U_COMMON_API UBool U_EXPORT2
145159umtx_initImplPreInit (UInitOnce &uio) {
160+ #if U_HAVE_ATOMICS
146161 std::call_once (*pInitFlag, umtx_init);
147162 std::unique_lock<std::mutex> lock (*initMutex);
163+ #endif
148164 if (umtx_loadAcquire (uio.fState ) == 0 ) {
149165 umtx_storeRelease (uio.fState , 1 );
150166 return true ; // Caller will next call the init function.
151167 } else {
168+ #if U_HAVE_ATOMICS
152169 while (umtx_loadAcquire (uio.fState ) == 1 ) {
153170 // Another thread is currently running the initialization.
154171 // Wait until it completes.
155172 initCondition->wait (lock);
156173 }
157174 U_ASSERT (uio.fState == 2 );
175+ #endif
158176 return false ;
159177 }
160178}
@@ -168,11 +186,13 @@ umtx_initImplPreInit(UInitOnce &uio) {
168186
169187U_COMMON_API void U_EXPORT2
170188umtx_initImplPostInit (UInitOnce &uio) {
189+ #if U_HAVE_ATOMICS
171190 {
172191 std::unique_lock<std::mutex> lock (*initMutex);
173192 umtx_storeRelease (uio.fState , 2 );
174193 }
175194 initCondition->notify_all ();
195+ #endif
176196}
177197
178198U_NAMESPACE_END
0 commit comments