U_NAMESPACE_BEGIN U_COMMON_API UBool U_EXPORT2 umtx_initImplPreInit(UInitOnce &uio) { for (;;) { int32_t previousState = InterlockedCompareExchange( (LONG volatile *) // this is the type given in the API doc for this function. &uio.fState, // Destination 1, // Exchange Value 0); // Compare value if (previousState == 0) { return true; // Caller will next call the init function. // Current state == 1. } else if (previousState == 2) { // Another thread already completed the initialization. // We can simply return FALSE, indicating no // further action is needed by the caller. return FALSE; } else { // Another thread is currently running the initialization. // Wait until it completes. do { Sleep(1); previousState = umtx_loadAcquire(uio.fState); } while (previousState == 1); } } }
int32_t SharedObject::getRefCount() const { return umtx_loadAcquire(refCount); }