void FreeList<Chunk>::remove_chunk(Chunk*fc) { assert_proper_lock_protection(); assert(head() != NULL, "Remove from empty list"); assert(fc != NULL, "Remove a NULL chunk"); assert(size() == fc->size(), "Wrong list"); assert(head() == NULL || head()->prev() == NULL, "list invariant"); assert(tail() == NULL || tail()->next() == NULL, "list invariant"); Chunk* prevFC = fc->prev(); Chunk* nextFC = fc->next(); if (nextFC != NULL) { // The chunk fc being removed has a "next". Set the "next" to the // "prev" of fc. nextFC->link_prev(prevFC); } else { // removed tail of list link_tail(prevFC); } if (prevFC == NULL) { // removed head of list link_head(nextFC); assert(nextFC == NULL || nextFC->prev() == NULL, "Prev of head should be NULL"); } else { prevFC->link_next(nextFC); assert(tail() != prevFC || prevFC->next() == NULL, "Next of tail should be NULL"); } decrement_count(); assert(((head() == NULL) + (tail() == NULL) + (count() == 0)) % 3 == 0, "H/T/C Inconsistency"); // clear next and prev fields of fc, debug only NOT_PRODUCT( fc->link_prev(NULL); fc->link_next(NULL); )
static x_boolean release_block(t_mchecker mc, t_block b, x_boolean stop, x_boolean discard) { x_boolean result; result = check_block(b, stop); x_mutex_lock(test_mutex, x_eternal); x_list_remove(b); decrement_count(b, b->size); if (discard) { total_discarded += 1; if (total_discarded % 1000 == 0) { oempa("Discarding Wonka Chunk %d...\n", total_discarded); } discardMem(b); } else { releaseMem(b); } x_mutex_unlock(test_mutex); return result; }
inline void increment_count(const size_t i, const int begin, const int end) { assert(begin >= 0); assert(end >= 0 && end >= begin); COUNTER_TYPE *p((COUNTER_TYPE *)this + i); if (*p == COUNTER_MAX) { // do not add, remove others for (size_t j(begin); j <= (size_t)end; ++j) if (j != i) decrement_count(j); } else *p = *p + 1; }
Chunk_t* FreeList<Chunk_t>::get_chunk_at_head() { assert_proper_lock_protection(); assert(head() == NULL || head()->prev() == NULL, "list invariant"); assert(tail() == NULL || tail()->next() == NULL, "list invariant"); Chunk_t* fc = head(); if (fc != NULL) { Chunk_t* nextFC = fc->next(); if (nextFC != NULL) { // The chunk fc being removed has a "next". Set the "next" to the // "prev" of fc. nextFC->link_prev(NULL); } else { // removed tail of list link_tail(NULL); } link_head(nextFC); decrement_count(); } assert(head() == NULL || head()->prev() == NULL, "list invariant"); assert(tail() == NULL || tail()->next() == NULL, "list invariant"); return fc; }
// Remove this chunk from the list void FreeList::removeChunk(FreeChunk*fc) { assert_proper_lock_protection(); assert(head() != NULL, "Remove from empty list"); assert(fc != NULL, "Remove a NULL chunk"); assert(size() == fc->size(), "Wrong list"); assert(head() == NULL || head()->prev() == NULL, "list invariant"); assert(tail() == NULL || tail()->next() == NULL, "list invariant"); FreeChunk* prevFC = fc->prev(); FreeChunk* nextFC = fc->next(); if (nextFC != NULL) { // The chunk fc being removed has a "next". Set the "next" to the // "prev" of fc. nextFC->linkPrev(prevFC); } else { // removed tail of list link_tail(prevFC); } if (prevFC == NULL) { // removed head of list link_head(nextFC); assert(nextFC == NULL || nextFC->prev() == NULL, "Prev of head should be NULL"); } else { prevFC->linkNext(nextFC); assert(tail() != prevFC || prevFC->next() == NULL, "Next of tail should be NULL"); } decrement_count(); #define TRAP_CODE 1 #if TRAP_CODE if (head() == NULL) { guarantee(tail() == NULL, "INVARIANT"); guarantee(count() == 0, "INVARIANT"); } #endif // clear next and prev fields of fc, debug only NOT_PRODUCT( fc->linkPrev(NULL); fc->linkNext(NULL); )