/*! ****************************************************************************** @Function RMAN_CreateBucket ******************************************************************************/ IMG_RESULT RMAN_CreateBucket( IMG_HANDLE * phResBHandle ) { RMAN_sBucket * psBucket; IMG_UINT32 i; IMG_RESULT i32Result; IMG_ASSERT(gInitialised); /* Allocate a bucket structure...*/ psBucket = IMG_MALLOC(sizeof(*psBucket)); IMG_ASSERT(psBucket != IMG_NULL); if (psBucket == IMG_NULL) { return IMG_ERROR_OUT_OF_MEMORY; } IMG_MEMSET(psBucket, 0, sizeof(*psBucket)); /* Intialise the resource list...*/ DQ_init(&psBucket->sResList); /* The start allocating resource ids at the first...*/ i32Result = IDGEN_CreateContext(RMAN_MAX_ID, RMAN_ID_BLOCKSIZE, IMG_FALSE, &psBucket->hIdGenerator); if(i32Result != IMG_SUCCESS) { IMG_FREE(psBucket); IMG_ASSERT(!"failed to create IDGEN context"); return i32Result; } /* Locate free bucket index within the table...*/ SYSOSKM_DisableInt(); for (i=0; i<RMAN_CRESID_MAX_BUCKET_INDEX; i++) { if (gapsBucket[i] == IMG_NULL) { break; } } if (i >= RMAN_CRESID_MAX_BUCKET_INDEX) { SYSOSKM_EnableInt(); IDGEN_DestroyContext(psBucket->hIdGenerator); IMG_FREE(psBucket); IMG_ASSERT(!"No free buckets left"); return IMG_ERROR_GENERIC_FAILURE; } /* Allocate bucket index...*/ psBucket->ui32BucketIndex = i; gapsBucket[i] = psBucket; SYSOSKM_EnableInt(); /* Return the bucket handle...*/ *phResBHandle = psBucket; return IMG_SUCCESS; }
/*! ****************************************************************************** @Function RMAN_DestroyBucket ******************************************************************************/ IMG_VOID RMAN_DestroyBucket( IMG_HANDLE hResBHandle ) { RMAN_sBucket * psBucket = (RMAN_sBucket *)hResBHandle; IMG_ASSERT(gInitialised); IMG_ASSERT(psBucket != IMG_NULL); if (psBucket== IMG_NULL) { return; } IMG_ASSERT(psBucket->ui32BucketIndex < RMAN_CRESID_MAX_BUCKET_INDEX); IMG_ASSERT(gapsBucket[psBucket->ui32BucketIndex] != IMG_NULL); /* Free all resources from the bucket...*/ RMAN_FreeResources(hResBHandle, RMAN_TYPE_P1); RMAN_FreeResources(hResBHandle, RMAN_TYPE_P2); RMAN_FreeResources(hResBHandle, RMAN_TYPE_P3); RMAN_FreeResources(hResBHandle, RMAN_ALL_TYPES); /* free sticky resources last: other resources are dependent on them */ RMAN_FreeResources(hResBHandle, RMAN_STICKY); /* Use proper locking around global buckets. */ SYSOSKM_DisableInt(); /* Free from array of bucket pointers...*/ gapsBucket[psBucket->ui32BucketIndex] = IMG_NULL; SYSOSKM_EnableInt(); /* Free the bucket itself...*/ IDGEN_DestroyContext(psBucket->hIdGenerator); IMG_FREE(psBucket); }
/*! ****************************************************************************** @Function POOL_PoolDestroy ******************************************************************************/ IMG_RESULT POOL_PoolDestroy( IMG_HANDLE hPoolHandle ) { POOL_sResPool * psResPool = hPoolHandle; POOL_sResource * psResource; POOL_sResource * psCloneResource; IMG_UINT32 ui32Result; IMG_ASSERT(gInitialised); IMG_ASSERT(psResPool != IMG_NULL); if (!gInitialised || psResPool == IMG_NULL) { ui32Result = IMG_ERROR_INVALID_PARAMETERS; goto error_nolock; } /* Lock the pool...*/ SYSOSKM_LockMutex(psResPool->hMutexHandle); /* Disable interrupts. */ SYSOSKM_DisableInt(); /* Remove the pool from the active list...*/ LST_remove(&gsPoolList, psResPool); /* Enable interrupts. */ SYSOSKM_EnableInt(); /* Destroy any resources in the free list...*/ psResource = (POOL_sResource *)LST_removeHead(&psResPool->sFreeResList); while (psResource != IMG_NULL) { psResource->pfnDestructor(psResource->pvParam); IMG_FREE(psResource); psResource = (POOL_sResource *)LST_removeHead(&psResPool->sFreeResList); } /* Destroy any resources in the active list...*/ psResource = (POOL_sResource *)LST_removeHead(&psResPool->sActResList); while (psResource != IMG_NULL) { psCloneResource = (POOL_sResource *)LST_removeHead(&psResource->sCloneResList); while (psCloneResource != IMG_NULL) { /* If we created a copy of the resources pvParam then free it...*/ if (psCloneResource->pvParam != IMG_NULL) { IMG_FREE(psCloneResource->pvParam ); } IMG_FREE(psCloneResource); psCloneResource = (POOL_sResource *)LST_removeHead(&psResource->sCloneResList); } /* Call the resource destructor...*/ psResource->pfnDestructor(psResource->pvParam); IMG_FREE(psResource); psResource = (POOL_sResource *)LST_removeHead(&psResPool->sActResList); } /* Destroy the context for the Id generator...*/ if (psResPool->hIdGenHandle != IMG_NULL) { ui32Result = IDGEN_DestroyContext(psResPool->hIdGenHandle); IMG_ASSERT(ui32Result == IMG_SUCCESS); } /* Unlock the pool...*/ SYSOSKM_UnlockMutex(psResPool->hMutexHandle); /* Destroy mutex...*/ SYSOSKM_DestroyMutex(psResPool->hMutexHandle); /* Free the pool structure */ IMG_FREE(psResPool); return IMG_SUCCESS; error_nolock: return ui32Result; }