예제 #1
0
/*!
******************************************************************************

 @Function                POOL_PoolCreate

******************************************************************************/
IMG_RESULT POOL_PoolCreate(
    IMG_HANDLE *  phPoolHandle
)
{
    POOL_sResPool *  psResPool;
    IMG_UINT32       ui32Result;

    IMG_ASSERT(gInitialised);

    /* Allocate a pool structure...*/
    psResPool = IMG_MALLOC(sizeof(*psResPool));
    IMG_ASSERT(psResPool != IMG_NULL);
    if (psResPool == IMG_NULL)
    {
        return IMG_ERROR_OUT_OF_MEMORY;
    }
    IMG_MEMSET(psResPool, 0, sizeof(*psResPool));

    /* Initialise the pool info...*/
    LST_init(&psResPool->sFreeResList);
    LST_init(&psResPool->sActResList);

    /* Create mutex...*/
    ui32Result = SYSOSKM_CreateMutex(&psResPool->hMutexHandle);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error_create_mutex;
    }

    /* Create context for the Id generator...*/
    ui32Result = IDGEN_CreateContext(POOL_IDGEN_MAX_ID, POOL_IDGEN_BLOCK_SIZE,IMG_FALSE, &psResPool->hIdGenHandle);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error_create_context;
    }

    /* Disable interrupts.  */
    SYSOSKM_DisableInt();

    /* Add to list of pools...*/
    LST_add(&gsPoolList, psResPool);

    /* Enable interrupts.  */
    SYSOSKM_EnableInt();

    /* Return handle to pool...*/
    *phPoolHandle = psResPool;

    return IMG_SUCCESS;

    /* Error handling. */
error_create_context:
    SYSOSKM_DestroyMutex(psResPool->hMutexHandle);
error_create_mutex:
    IMG_FREE(psResPool);

    return ui32Result;
}
예제 #2
0
/*!
******************************************************************************

 @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;
}