// Places value and status at key if there is no value at key or if cache // entry for key is in progress. Otherwise, it leaves the current value and // status there. // On entry. gCacheMutex must not be held. value must be // included in the reference count of the object to which it points. // On exit, value and status are changed to what was already in the cache if // something was there and not in progress. Otherwise, value and status are left // unchanged in which case they are placed in the cache on a best-effort basis. // Caller must call removeRef() on value. void UnifiedCache::_putIfAbsentAndGet( const CacheKeyBase &key, const SharedObject *&value, UErrorCode &status) const { Mutex lock(&gCacheMutex); const UHashElement *element = uhash_find(fHashtable, &key); if (element != NULL && !_inProgress(element)) { _fetch(element, value, status); return; } if (element == NULL) { UErrorCode putError = U_ZERO_ERROR; // best-effort basis only. _putNew(key, value, status, putError); } else { _put(element, value, status); } // Run an eviction slice. This will run even if we added a master entry // which doesn't increase the unused count, but that is still o.k _runEvictionSlice(); }
void UnifiedCache::decrementItemsInUseWithLockingAndEviction() const { Mutex mutex(&gCacheMutex); decrementItemsInUse(); _runEvictionSlice(); }
void UnifiedCache::handleUnreferencedObject() const { Mutex lock(gCacheMutex()); --fNumValuesInUse; _runEvictionSlice(); }