mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-14 17:24:01 +00:00
ICU-10331 fix immediate issue on cygwin, mingw still broken. also fix warnings and spaces
X-SVN-Rev: 34133
This commit is contained in:
parent
bc031bb637
commit
80597323f8
2 changed files with 22 additions and 20 deletions
|
@ -61,7 +61,10 @@ static UMutex globalMutex = U_MUTEX_INITIALIZER;
|
|||
|
||||
U_CAPI UBool U_EXPORT2 umtx_initImplPreInit(UInitOnce &uio) {
|
||||
for (;;) {
|
||||
int32_t previousState = InterlockedCompareExchange(
|
||||
int32_t previousState = InterlockedCompareExchange(
|
||||
#if (U_PLATFORM == U_PF_MINGW) || (U_PLATFORM == U_PF_CYGWIN)
|
||||
(LONG volatile *) // this is the type given in the API doc for this function.
|
||||
#endif
|
||||
&uio.fState, // Destination
|
||||
1, // Exchange Value
|
||||
0); // Compare value
|
||||
|
@ -131,7 +134,7 @@ umtx_unlock(UMutex* mutex)
|
|||
//
|
||||
//-------------------------------------------------------------------------------------------
|
||||
|
||||
# include <pthread.h>
|
||||
# include <pthread.h>
|
||||
|
||||
// Each UMutex consists of a pthread_mutex_t.
|
||||
// All are statically initialized and ready for use.
|
||||
|
@ -206,7 +209,7 @@ UBool umtx_initImplPreInit(UInitOnce &uio) {
|
|||
// This function is called by the thread that ran an initialization function,
|
||||
// just after completing the function.
|
||||
// Some threads may be waiting on the condition, requiring the broadcast wakeup.
|
||||
// Some threads may be racing to test the fState variable outside of the mutex,
|
||||
// Some threads may be racing to test the fState variable outside of the mutex,
|
||||
// requiring the use of store/release when changing its value.
|
||||
//
|
||||
// success: True: the inialization succeeded. No further calls to the init
|
||||
|
@ -227,7 +230,7 @@ void umtx_initOnceReset(UInitOnce &uio) {
|
|||
// Not a thread safe function, we can use an ordinary assignment.
|
||||
uio.fState = 0;
|
||||
}
|
||||
|
||||
|
||||
// End of POSIX specific umutex implementation.
|
||||
|
||||
#else // Platform #define chain.
|
||||
|
@ -292,8 +295,8 @@ umtx_storeRelease(atomic_int32_t &var, int32_t val) {
|
|||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
U_DEPRECATED void U_EXPORT2
|
||||
u_setMutexFunctions(const void * /*context */, UMtxInitFn *, UMtxFn *,
|
||||
U_DEPRECATED void U_EXPORT2
|
||||
u_setMutexFunctions(const void * /*context */, UMtxInitFn *, UMtxFn *,
|
||||
UMtxFn *, UMtxFn *, UErrorCode *status) {
|
||||
if (U_SUCCESS(*status)) {
|
||||
*status = U_UNSUPPORTED_ERROR;
|
||||
|
@ -311,4 +314,3 @@ u_setAtomicIncDecFunctions(const void * /*context */, UMtxAtomicFn *, UMtxAtomic
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ struct UInitOnce;
|
|||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Low Level Atomic Operations.
|
||||
* Low Level Atomic Operations.
|
||||
* Compiler dependent. Not operating system dependent.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
@ -46,20 +46,20 @@ typedef std::atomic<int32_t> atomic_int32_t;
|
|||
|
||||
inline int32_t umtx_loadAcquire(atomic_int32_t &var) {
|
||||
return var.load(std::memory_order_acquire);
|
||||
};
|
||||
}
|
||||
|
||||
inline void umtx_storeRelease(atomic_int32_t &var, int32_t val) {
|
||||
var.store(val, std::memory_order_release);
|
||||
};
|
||||
}
|
||||
|
||||
inline int32_t umtx_atomic_inc(atomic_int32_t *var) {
|
||||
return var->fetch_add(1) + 1;
|
||||
}
|
||||
|
||||
|
||||
inline int32_t umtx_atomic_dec(atomic_int32_t *var) {
|
||||
return var->fetch_sub(1) - 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#elif U_PLATFORM_HAS_WIN32_API
|
||||
|
||||
|
@ -203,7 +203,7 @@ inline void umtx_initOnce(UInitOnce &uio, void (*fp)()) {
|
|||
inline void umtx_initOnce(UInitOnce &uio, void (*fp)(UErrorCode &), UErrorCode &errCode) {
|
||||
if (U_FAILURE(errCode)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (umtx_loadAcquire(uio.fState) != 2 && umtx_initImplPreInit(uio)) {
|
||||
// We run the initialization.
|
||||
(*fp)(errCode);
|
||||
|
@ -234,7 +234,7 @@ template<class T> void umtx_initOnce(UInitOnce &uio, void (*fp)(T), T context) {
|
|||
template<class T> void umtx_initOnce(UInitOnce &uio, void (*fp)(T, UErrorCode &), T context, UErrorCode &errCode) {
|
||||
if (U_FAILURE(errCode)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (umtx_loadAcquire(uio.fState) != 2 && umtx_initImplPreInit(uio)) {
|
||||
// We run the initialization.
|
||||
(*fp)(context, errCode);
|
||||
|
@ -270,12 +270,12 @@ template<class T> void umtx_initOnce(UInitOnce &uio, void (*fp)(T, UErrorCode &)
|
|||
/* For CRITICAL_SECTION */
|
||||
|
||||
/*
|
||||
* Note: there is an earlier include of windows.h in this file, but it is in
|
||||
* Note: there is an earlier include of windows.h in this file, but it is in
|
||||
* different conditionals.
|
||||
* This one is needed if we are using C++11 for atomic ops, but
|
||||
* win32 APIs for Critical Sections.
|
||||
*/
|
||||
|
||||
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# define VC_EXTRALEAN
|
||||
# define NOUSER
|
||||
|
@ -317,8 +317,8 @@ typedef struct UMutex UMutex;
|
|||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Unknow platform type.
|
||||
/*
|
||||
* Unknow platform type.
|
||||
* This is an error condition. ICU requires mutexes.
|
||||
*/
|
||||
|
||||
|
@ -327,7 +327,7 @@ typedef struct UMutex UMutex;
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************
|
||||
*
|
||||
* Mutex Implementation function declaratations.
|
||||
|
@ -341,7 +341,7 @@ typedef struct UMutex UMutex;
|
|||
* the global ICU mutex. Recursive locks are an error
|
||||
* and may cause a deadlock on some platforms.
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2 umtx_lock(UMutex* mutex);
|
||||
U_INTERNAL void U_EXPORT2 umtx_lock(UMutex* mutex);
|
||||
|
||||
/* Unlock a mutex.
|
||||
* @param mutex The given mutex to be unlocked. Pass NULL to specify
|
||||
|
|
Loading…
Add table
Reference in a new issue