void allocator_destroy(allocator_t *allocator)
{
  while(!dllist_is_empty(&allocator->chunks)) {
    dllist_link *l = dllist_rem_head(&allocator->chunks);
    chunk_t *tmp = DLLIST_ELEMENT(l, chunk_t, link);
    chunk_destroy(tmp);
    free(tmp);
  }

  pthread_mutex_destroy(&allocator->lock);
}
Esempio n. 2
0
static
IMG_VOID _SyncConnectionUnref(SYNC_CONNECTION_DATA *psSyncConnectionData)
{
	IMG_UINT32 ui32RefCount;

	OSLockAcquire(psSyncConnectionData->hLock);
	ui32RefCount = --psSyncConnectionData->ui32RefCount;
	OSLockRelease(psSyncConnectionData->hLock);

	if (ui32RefCount == 0)
	{
		SYNC_REFCOUNT_PRINT("%s: Sync connection %p, refcount = %d",
							__FUNCTION__, psSyncConnectionData, ui32RefCount);

		PVR_ASSERT(dllist_is_empty(&psSyncConnectionData->sListHead));
		OSLockDestroy(psSyncConnectionData->hLock);
		OSFreeMem(psSyncConnectionData);
	}
	else
	{
		SYNC_REFCOUNT_PRINT("%s: Sync connection %p, refcount = %d",
							__FUNCTION__, psSyncConnectionData, ui32RefCount);
	}
}
uint32_t allocator_shrink(allocator_t *allocator)
{
  uint32_t count = 0;

  dllist rem_list;
  dllist_init(&rem_list);

  pthread_mutex_lock(&allocator->lock);
  dllist_link *l = allocator->chunks.head;
  for (; l ;) {
    chunk_t *tmp = DLLIST_ELEMENT(l, chunk_t, link);
    dllist_link *nl = l->next;
    if (chunk_get_count(tmp) == tmp->nr_blocks) {
      allocator->chunks_count--;
      dllist_rem(&allocator->chunks, l);

      if (allocator->alloc_chunk == l) {
        allocator->alloc_chunk = allocator->chunks.head;
      }

      dllist_iat(&rem_list, l);
      count += tmp->nr_blocks;
    }
    l = nl;
  }
  pthread_mutex_unlock(&allocator->lock);

  while (!dllist_is_empty(&rem_list)) {
    dllist_link *head = dllist_rem_head(&rem_list);
    chunk_t *tmp = DLLIST_ELEMENT(head, chunk_t, link);
    chunk_destroy(tmp);
    free(tmp);
  }

  return count;
}