void removeBackRef(BackRefIdx backRefIdx) { MALLOC_ASSERT(!backRefIdx.isInvalid(), ASSERT_TEXT); MALLOC_ASSERT(backRefIdx.getMaster()<=backRefMaster->lastUsed && backRefIdx.getOffset()<BR_MAX_CNT, ASSERT_TEXT); BackRefBlock *currBlock = backRefMaster->backRefBl[backRefIdx.getMaster()]; FreeObject *freeObj = (FreeObject*)((uintptr_t)currBlock + sizeof(BackRefBlock) + backRefIdx.getOffset()*sizeof(void*)); MALLOC_ASSERT(((uintptr_t)freeObj>(uintptr_t)currBlock && (uintptr_t)freeObj<(uintptr_t)currBlock + slabSize), ASSERT_TEXT); { MallocMutex::scoped_lock lock(currBlock->blockMutex); freeObj->next = currBlock->freeList; MALLOC_ASSERT(!freeObj->next || ((uintptr_t)freeObj->next > (uintptr_t)currBlock && (uintptr_t)freeObj->next < (uintptr_t)currBlock + slabSize), ASSERT_TEXT); currBlock->freeList = freeObj; currBlock->allocatedCount--; } // TODO: do we need double-check here? if (!currBlock->addedToForUse && currBlock!=backRefMaster->active) { MallocMutex::scoped_lock lock(masterMutex); if (!currBlock->addedToForUse && currBlock!=backRefMaster->active) backRefMaster->addToForUseList(currBlock); } }
void setBackRef(BackRefIdx backRefIdx, void *newPtr) { MALLOC_ASSERT(backRefIdx.getMaster()<=backRefMaster->lastUsed && backRefIdx.getOffset()<BR_MAX_CNT, ASSERT_TEXT); *(void**)((uintptr_t)backRefMaster->backRefBl[backRefIdx.getMaster()] + sizeof(BackRefBlock) + backRefIdx.getOffset()*sizeof(void*)) = newPtr; }