core/heap.c
/* Special heap iterator.  Initialized with special_heap_iterator_start(), which
 * grabs the heap lock (regardless of whether synch is used for allocs), and
 * destroyed with special_heap_iterator_stop() to release the lock.
 * If the special heap uses no lock for alloc, it is up to the caller
 * to prevent race conditions causing problems.
 * Accessor special_heap_iterator_next() should be called only when
 * predicate special_heap_iterator_hasnext() is true.
 * Any mutation of the heap while iterating will result in a deadlock
 * for heaps that use locks for alloc, except for individual freeing,
 * which will proceed w/o trying to grab the lock a second time.
 * FIXME: could generalize to regular heaps if a use arises.
 */
Special heap iterator.  Initialized with special_heap_iterator_start(), which
grabs the heap lock (regardless of whether synch is used for allocs), and
destroyed with special_heap_iterator_stop() to release the lock.
If the special heap uses no lock for alloc, it is up to the caller
to prevent race conditions causing problems.
Accessor special_heap_iterator_next() should be called only when
predicate special_heap_iterator_hasnext() is true.
Any mutation of the heap while iterating will result in a deadlock
for heaps that use locks for alloc, except for individual freeing,
which will proceed w/o trying to grab the lock a second time.
FIXME: could generalize to regular heaps if a use arises.
Special heap iterator . Initialized with special_heap_iterator_start () which grabs the heap lock ( regardless of whether synch is used for allocs ) and destroyed with special_heap_iterator_stop () to release the lock . If the special heap uses no lock for alloc it is up to the caller to prevent race conditions causing problems . Accessor special_heap_iterator_next () should be called only when predicate special_heap_iterator_hasnext () is true . Any mutation of the heap while iterating will result in a deadlock for heaps that use locks for alloc except for individual freeing which will proceed w / o trying to grab the lock a second time . FIXME : could generalize to regular heaps if a use arises .
void
special_heap_iterator_start(void *heap, special_heap_iterator_t *shi)
{
    special_units_t *su = (special_units_t *) heap;
    ASSERT(heap != NULL);
    ASSERT(shi != NULL);
    mutex_lock(&su->lock);
    shi->heap = heap;
    shi->next_unit = (void *) su->top_unit;
    su->in_iterator = true;
}
void special_heap_iterator_start ( void * heap , special_heap_iterator_t * shi ) { special_units_t * su = ( special_units_t * ) heap ; ASSERT ( heap != NULL ) ; ASSERT ( shi != NULL ) ; mutex_lock ( & su -> lock ) ; shi -> heap = heap ; shi -> next_unit = ( void * ) su -> top_unit ; su -> in_iterator = true ; }
Special heap iterator.
Special heap iterator .