void MemoryCache::insertInLRUList(Resource* resource) { // Make sure we aren't in some list already. ASSERT(!resource->m_nextInAllResourcesList && !resource->m_prevInAllResourcesList); ASSERT(resource->inCache()); ASSERT(resource->accessCount() > 0); LRUList* list = lruListFor(resource); resource->m_nextInAllResourcesList = list->m_head; if (list->m_head) list->m_head->m_prevInAllResourcesList = resource; list->m_head = resource; if (!resource->m_nextInAllResourcesList) list->m_tail = resource; #if !ASSERT_DISABLED // Verify that we are in now in the list like we should be. list = lruListFor(resource); bool found = false; for (Resource* current = list->m_head; current; current = current->m_nextInAllResourcesList) { if (current == resource) { found = true; break; } } ASSERT(found); #endif }
void MemoryCache::insertInLRUList(CachedResource& resource) { ASSERT(resource.inCache()); ASSERT(resource.accessCount() > 0); auto addResult = lruListFor(resource).add(&resource); ASSERT_UNUSED(addResult, addResult.isNewEntry); }
void MemoryCache::update(Resource* resource, size_t oldSize, size_t newSize, bool wasAccessed) { MemoryCacheEntry* entry = getEntryForResource(resource); if (!entry) return; // The object must now be moved to a different queue, since either its size or its accessCount has been changed, // and both of those are used to determine which LRU queue the resource should be in. if (oldSize) removeFromLRUList(entry, lruListFor(entry->m_accessCount, oldSize)); if (wasAccessed) entry->m_accessCount++; if (newSize) insertInLRUList(entry, lruListFor(entry->m_accessCount, newSize)); ptrdiff_t delta = newSize - oldSize; if (resource->hasClients()) { ASSERT(delta >= 0 || m_liveSize >= static_cast<size_t>(-delta) ); m_liveSize += delta; } else { ASSERT(delta >= 0 || m_deadSize >= static_cast<size_t>(-delta) ); m_deadSize += delta; } }
void MemoryCache::removeFromLRUList(Resource* resource) { // If we've never been accessed, then we're brand new and not in any list. if (!resource->accessCount()) return; #if !ASSERT_DISABLED unsigned oldListIndex = resource->m_lruIndex; #endif LRUList* list = lruListFor(resource); #if !ASSERT_DISABLED // Verify that the list we got is the list we want. ASSERT(resource->m_lruIndex == oldListIndex); // Verify that we are in fact in this list. bool found = false; for (Resource* current = list->m_head; current; current = current->m_nextInAllResourcesList) { if (current == resource) { found = true; break; } } ASSERT(found); #endif Resource* next = resource->m_nextInAllResourcesList; Resource* prev = resource->m_prevInAllResourcesList; if (!next && !prev && list->m_head != resource) return; resource->m_nextInAllResourcesList = 0; resource->m_prevInAllResourcesList = 0; if (next) next->m_prevInAllResourcesList = prev; else if (list->m_tail == resource) list->m_tail = prev; if (prev) prev->m_nextInAllResourcesList = next; else if (list->m_head == resource) list->m_head = next; }
void MemoryCache::removeFromLRUList(CachedResource& resource) { // If we've never been accessed, then we're brand new and not in any list. if (!resource.accessCount()) return; #if !ASSERT_DISABLED unsigned oldListIndex = resource.m_lruIndex; #endif LRUList& list = lruListFor(resource); // Verify that the list we got is the list we want. ASSERT(resource.m_lruIndex == oldListIndex); bool removed = list.remove(&resource); ASSERT_UNUSED(removed, removed); }