diff options
Diffstat (limited to 'src/VBox/Runtime/common/alloc/memcache.cpp')
-rw-r--r-- | src/VBox/Runtime/common/alloc/memcache.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/VBox/Runtime/common/alloc/memcache.cpp b/src/VBox/Runtime/common/alloc/memcache.cpp index 57282102..43285e67 100644 --- a/src/VBox/Runtime/common/alloc/memcache.cpp +++ b/src/VBox/Runtime/common/alloc/memcache.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2010 Oracle Corporation + * Copyright (C) 2006-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -122,6 +122,8 @@ typedef struct RTMEMCACHEINT bool fUseFreeList; /** Head of the page list. */ PRTMEMCACHEPAGE pPageHead; + /** Poiner to the insertion point in the page list. */ + PRTMEMCACHEPAGE volatile *ppPageNext; /** Constructor callback. */ PFNMEMCACHECTOR pfnCtor; /** Destructor callback. */ @@ -141,8 +143,8 @@ typedef struct RTMEMCACHEINT * These are marked as used in the allocation bitmaps. * * @todo This doesn't scale well when several threads are beating on the - * cache. Also, it totally doesn't work when we've got a - * constructor/destructor around or the objects are too small. */ + * cache. Also, it totally doesn't work when the objects are too + * small. */ PRTMEMCACHEFREEOBJ volatile pFreeTop; } RTMEMCACHEINT; @@ -209,6 +211,7 @@ RTDECL(int) RTMemCacheCreate(PRTMEMCACHE phMemCache, size_t cbObject, size_t cbA && !pfnCtor && !pfnDtor; pThis->pPageHead = NULL; + pThis->ppPageNext = &pThis->pPageHead; pThis->pfnCtor = pfnCtor; pThis->pfnDtor = pfnDtor; pThis->pvUser = pvUser; @@ -244,7 +247,8 @@ RTDECL(int) RTMemCacheDestroy(RTMEMCACHE hMemCache) return VINF_SUCCESS; AssertPtrReturn(pThis, VERR_INVALID_HANDLE); AssertReturn(pThis->u32Magic == RTMEMCACHE_MAGIC, VERR_INVALID_HANDLE); -#ifdef RT_STRICT + +#if 0 /*def RT_STRICT - don't require eveything to be freed. Caches are very convenient for lazy cleanup. */ uint32_t cFree = pThis->cFree; for (PRTMEMCACHEFREEOBJ pFree = pThis->pFreeTop; pFree && cFree < pThis->cTotal + 5; pFree = pFree->pNext) cFree++; @@ -332,16 +336,9 @@ static int rtMemCacheGrow(RTMEMCACHEINT *pThis) /* Make it the hint. */ ASMAtomicWritePtr(&pThis->pPageHint, pPage); - /* Link the page. */ - PRTMEMCACHEPAGE pPrevPage = pThis->pPageHead; - if (!pPrevPage) - ASMAtomicWritePtr(&pThis->pPageHead, pPage); - else - { - while (pPrevPage->pNext) - pPrevPage = pPrevPage->pNext; - ASMAtomicWritePtr(&pPrevPage->pNext, pPage); - } + /* Link the page in at the end of the list. */ + ASMAtomicWritePtr(pThis->ppPageNext, pPage); + pThis->ppPageNext = &pPage->pNext; /* Add it to the page counts. */ ASMAtomicAddS32(&pThis->cFree, cObjects); @@ -547,8 +544,7 @@ RTDECL(void) RTMemCacheFree(RTMEMCACHE hMemCache, void *pvObj) } else { - /* Note: Do *NOT* attempt to poison the object if we have a constructor - or/and destructor! */ + /* Note: Do *NOT* attempt to poison the object! */ /* * Find the cache page. The page structure is at the start of the page. |