heap->heap_increment = 16;
heap->heap_index = NULL;
heap->next_free = LAST_FREE;
+ _i965InitMutex(&heap->mutex);
return object_heap_expand(heap);
}
int object_heap_allocate( object_heap_p heap )
{
object_base_p obj;
+
+ _i965LockMutex(&heap->mutex);
if ( LAST_FREE == heap->next_free )
{
if( -1 == object_heap_expand( heap ) )
{
+ _i965UnlockMutex(&heap->mutex);
return -1; /* Out of memory */
}
}
obj = (object_base_p) (heap->heap_index + heap->next_free * heap->object_size);
heap->next_free = obj->next_free;
+ _i965UnlockMutex(&heap->mutex);
+
obj->next_free = ALLOCATED;
return obj->id;
}
object_base_p object_heap_lookup( object_heap_p heap, int id )
{
object_base_p obj;
+
+ _i965LockMutex(&heap->mutex);
if ( (id < heap->id_offset) || (id > (heap->heap_size+heap->id_offset)) )
{
+ _i965UnlockMutex(&heap->mutex);
return NULL;
}
id &= OBJECT_HEAP_ID_MASK;
obj = (object_base_p) (heap->heap_index + id * heap->object_size);
+ _i965UnlockMutex(&heap->mutex);
/* Check if the object has in fact been allocated */
if ( obj->next_free != ALLOCATED )
{
object_base_p obj;
int i = *iter + 1;
+ _i965LockMutex(&heap->mutex);
while ( i < heap->heap_size)
{
obj = (object_base_p) (heap->heap_index + i * heap->object_size);
if (obj->next_free == ALLOCATED)
{
+ _i965UnlockMutex(&heap->mutex);
*iter = i;
return obj;
}
i++;
}
+ _i965UnlockMutex(&heap->mutex);
*iter = i;
return NULL;
}
/* Check if the object has in fact been allocated */
ASSERT( obj->next_free == ALLOCATED );
+ _i965LockMutex(&heap->mutex);
obj->next_free = heap->next_free;
heap->next_free = obj->id & OBJECT_HEAP_ID_MASK;
+ _i965UnlockMutex(&heap->mutex);
}
}
{
object_base_p obj;
int i;
+
+ _i965DestroyMutex(&heap->mutex);
+
/* Check if heap is empty */
for (i = 0; i < heap->heap_size; i++)
{