-SharedObject::addRef(UBool fromWithinCache) const {
- umtx_atomic_inc(&totalRefCount);
-
- // Although items in use may not be correct immediately, it
- // will be correct eventually.
- if (umtx_atomic_inc(&hardRefCount) == 1 && cachePtr != NULL) {
- // If this object is cached, and the hardRefCount goes from 0 to 1,
- // then the increment must happen from within the cache while the
- // cache global mutex is locked. In this way, we can be rest assured
- // that data races can't happen if the cache performs some task if
- // the hardRefCount is zero while the global cache mutex is locked.
- (void)fromWithinCache; // Suppress unused variable warning in non-debug builds.
- U_ASSERT(fromWithinCache);
- cachePtr->incrementItemsInUse();
- }