Exemplo n.º 1
0
/*!
******************************************************************************

 @Function                POOL_PoolSetFreeCallback

******************************************************************************/
IMG_RESULT POOL_PoolSetFreeCallback(
    IMG_HANDLE    hPoolHandle,
    POOL_pfnFree  pfnFree
)
{
    POOL_sResPool *   psResPool = hPoolHandle;
    POOL_sResource *  psResource;
    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);

    psResPool->pfnFree = pfnFree;

    /* If free callback set...*/
    if (psResPool->pfnFree != IMG_NULL)
    {
        /* Move resources from free to active list...*/
        psResource = (POOL_sResource *)LST_removeHead(&psResPool->sFreeResList);
        while (psResource != IMG_NULL)
        {
            /* Add to active list...*/
            LST_add(&psResPool->sActResList, psResource);
            psResource->ui32RefCnt++;

            /* Unlock the pool...*/
            SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

            /* Call the free callback...*/
            psResPool->pfnFree(psResource->ui32ResId, psResource->pvParam);

            /* Lock the pool...*/
            SYSOSKM_LockMutex(psResPool->hMutexHandle);

            /* Get next free resource...*/
            psResource = (POOL_sResource *)LST_removeHead(&psResPool->sFreeResList);
        }
    }

    /* Unlock the pool...*/
    SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

    /* Return IMG_SUCCESS...*/
    return IMG_SUCCESS;

error_nolock:
    return ui32Result;
}
/*!
******************************************************************************

 @Function      perflog_WriteFile

 @Description

 Writes to the file.

 @Input    pFileHandler : file where data will be written

 @Input    uiMsg        : performance data

 @Return    IMG_SUCCESS in case when data has been written successfully,
            error code otherwise

******************************************************************************/
static IMG_RESULT perflog_WriteFile(perflog_FileHandler *pFileHandler, IMG_UINT64 uiMsg)
{
    perflog_Buffer  *psBuffer;

    if(pFileHandler == IMG_NULL)
    {
        REPORT(REPORT_MODULE_PERFLOG, REPORT_ERR,
                "Performance logger cannot clean file: invalid parameters");
        return IMG_ERROR_INVALID_PARAMETERS;
    }

    SYSOSKM_LockMutex(pFileHandler->hMutexHandle);

    //search for buffer that has place to store perf data
    psBuffer = LST_first(&pFileHandler->sBufferList);
    while(psBuffer)
    {
        if(psBuffer->stIter < psBuffer->stBufferSize)
        {
            break;
        }
        psBuffer = LST_next(psBuffer);
    }

    //new buffer is needed
    if(psBuffer == IMG_NULL)
    {
        IMG_RESULT result;

        //create new buffer
        if( (result = perflog_CreateBuffer(&psBuffer, ONE_BUFFER_SIZE)) != IMG_SUCCESS )
        {
            SYSOSKM_UnlockMutex(pFileHandler->hMutexHandle);
            REPORT(REPORT_MODULE_PERFLOG, REPORT_ERR,
                "Performance logger cannot allocate buffers");
            return result;
        }

        //add buffer to a list
        LST_add(&pFileHandler->sBufferList, psBuffer);
    }

    //write data
    psBuffer->pui64Buffer[(psBuffer->stIter)++] = uiMsg;

    SYSOSKM_UnlockMutex(pFileHandler->hMutexHandle);

    return IMG_SUCCESS;
}
Exemplo n.º 3
0
/*!
******************************************************************************

 @Function				SYSDEVU_RegisterDevices

******************************************************************************/
IMG_RESULT SYSDEVU_RegisterDevice(
	SYSDEVU_sInfo *psInfo
)
{
	IMG_UINT32			ui32Result;

	IMG_ASSERT(gSysDevInitialised);
	/* Initialise parts of the device info structure...*/
	psInfo->bDevLocated	= IMG_FALSE;
	psInfo->pvLocParam = IMG_NULL;

	SYSOSKM_LockMutex(hNextDeviceIdMutex);
	psInfo->ui32DeviceId = gui32NextDeviceId;
	gui32NextDeviceId += 1;
	SYSOSKM_UnlockMutex(hNextDeviceIdMutex);

	/* Register the device with the device manager...*/
	ui32Result = DMANKM_RegisterDevice(psInfo->sDevInfo.pszDeviceName, psInfo->sDevInfo.pfnDevRegister);
	IMG_ASSERT(ui32Result == IMG_SUCCESS);
	if (ui32Result != IMG_SUCCESS)
	{
		return ui32Result;
	}

	/* Initialise the devices...*/
	LST_add(&gsDevList, psInfo);
	gui32NoDevices++;

	/* Return success...*/
	return IMG_SUCCESS;
}
/*!
******************************************************************************

 @Function      perflog_CleanFile

 @Description

 Truncates performance file to zero length.

 @Input    pFileHandler : file to be cleand

 @Return    IMG_SUCCESS in case when file has been cleand successfully,
            error code otherwise

******************************************************************************/
static IMG_RESULT perflog_CleanFile(perflog_FileHandler *pFileHandler)
{
    perflog_Buffer  *psBuffer;

    if(pFileHandler == IMG_NULL)
    {
        REPORT(REPORT_MODULE_PERFLOG, REPORT_ERR,
                "Performance logger cannot clean file: invalid parameters");
        return IMG_ERROR_INVALID_PARAMETERS;
    }

    SYSOSKM_LockMutex(pFileHandler->hMutexHandle);

    //removes all buffers
    psBuffer = LST_removeHead(&pFileHandler->sBufferList);
    while(psBuffer)
    {
        perflog_DestroyBuffer(psBuffer);

        psBuffer = LST_removeHead(&pFileHandler->sBufferList);
    }

    SYSOSKM_UnlockMutex(pFileHandler->hMutexHandle);

    return IMG_SUCCESS;
}
/*!
******************************************************************************

 @Function      perflog_DeinitialiseFile

 @Description

 Deinitialises file.

 @Input    pFileHandler : file to be deinitialised

 @Return    IMG_SUCCESS in case when file has been deinitialised successfully,
            error code otherwise

******************************************************************************/
static IMG_VOID perflog_DeinitialiseFile(
    perflog_FileHandler *pFileHandler
)
{
    if(pFileHandler == IMG_NULL)
    {
        REPORT(REPORT_MODULE_PERFLOG, REPORT_ERR,
                "Performance logger cannot deinitialise file: invalid parameters");
        return;
    }

    SYSOSKM_LockMutex(pFileHandler->hMutexHandle);

    //removes file from debug filesystem...
    debugfs_remove(pFileHandler->psFile);

    //removes all internal structures
    perflog_CleanFile(pFileHandler);

    SYSOSKM_UnlockMutex(pFileHandler->hMutexHandle);

    //and file mutex
    SYSOSKM_DestroyMutex(pFileHandler->hMutexHandle);

}
Exemplo n.º 6
0
/*!
******************************************************************************

 @Function                POOL_ResDestroy1

******************************************************************************/
IMG_RESULT POOL_ResDestroy1(
    IMG_HANDLE  hPoolHandle,
    IMG_UINT32  ui32ResId,
    IMG_BOOL    bForce
)
{
    POOL_sResPool *  psResPool = hPoolHandle;
    IMG_UINT32       ui32Result;
    IMG_HANDLE       hPoolResHandle;

    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);

    ui32Result = IDGEN_GetHandle(psResPool->hIdGenHandle, ui32ResId, &hPoolResHandle);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        /* Unlock the pool...*/
        SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

        return ui32Result;
    }

    /* Unlock the pool...*/
    SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

    /* Call on to destroy resource...*/
    return POOL_ResDestroy(hPoolResHandle, bForce);

error_nolock:
    return ui32Result;
}
Exemplo n.º 7
0
/*!
******************************************************************************

 @Function				rman_GetResource

******************************************************************************/
static IMG_VOID * rman_GetResource(
    IMG_HANDLE				hResBHandle,
    IMG_UINT32				ui32ResId,
    IMG_UINT32				ui32TypeId,
    IMG_HANDLE *			phResHandle
)
{
    RMAN_sBucket *				psBucket = (RMAN_sBucket *) hResBHandle;
    RMAN_sResource *			psResource;
    IMG_RESULT					i32Result;

    IMG_ASSERT(ui32ResId <= RMAN_CRESID_MAX_RES_ID);

    /* Loop over the resources in this bucket till we find the required id...*/
    //SYSOSKM_DisableInt();
    SYSOSKM_LockMutex(globalMutext);
    i32Result = IDGEN_GetHandle(psBucket->hIdGenerator, ui32ResId, (void**)&psResource);
    SYSOSKM_UnlockMutex(globalMutext);
    //SYSOSKM_EnableInt();
    if(i32Result != IMG_SUCCESS)
    {
        IMG_ASSERT(!"failed to get RMAN resource");
        return IMG_NULL;
    }

    /* If the resource handle is required...*/
    if (phResHandle != IMG_NULL)
    {
        /* Return it...*/
        *phResHandle = psResource;
    }

    /* If the resource was not found...*/
    IMG_ASSERT(psResource != IMG_NULL);
    IMG_ASSERT((IMG_VOID*)psResource != &psBucket->sResList);
    if ( (psResource == IMG_NULL) || ((IMG_VOID*)psResource == &psBucket->sResList) )
    {
        return IMG_NULL;
    }

    /* Cross check the type...*/
    IMG_ASSERT(ui32TypeId == psResource->ui32TypeId);

    /* Return the resource....*/
    return psResource->pvParam;
}
Exemplo n.º 8
0
/*!
******************************************************************************

 @Function                POOL_ResAlloc

******************************************************************************/
IMG_RESULT POOL_ResAlloc(
    IMG_HANDLE  hPoolHandle,
    IMG_HANDLE  hPoolResHandle
)
{
    POOL_sResPool *   psResPool  = hPoolHandle;
    POOL_sResource *  psResource = hPoolResHandle;
    IMG_UINT32              ui32Result;

    IMG_ASSERT(gInitialised);
    IMG_ASSERT(psResPool != IMG_NULL);
    IMG_ASSERT(hPoolResHandle != IMG_NULL);

    if (!gInitialised ||
        psResPool == IMG_NULL ||
        hPoolResHandle == IMG_NULL)
    {
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error_nolock;
    }

    /* Lock the pool...*/
    SYSOSKM_LockMutex(psResPool->hMutexHandle);

    /* Remove resource from free list...*/
    LST_remove(&psResPool->sFreeResList, psResource);

    /* Add to active list...*/
    LST_add(&psResPool->sActResList, psResource);
    psResource->ui32RefCnt++;

    /* Unlock the pool...*/
    SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

    /* Return IMG_SUCCESS...*/
    return IMG_SUCCESS;

error_nolock:
    return ui32Result;
}
/*!
 ******************************************************************************

 @Function				DMANKM_UnlockDeviceContext

 ******************************************************************************/
IMG_VOID DMANKM_UnlockDeviceContext(
		IMG_HANDLE hDevHandle) {
	/* Release mutex */
	SYSOSKM_UnlockMutex(((DMANKM_sDevContext *) hDevHandle)->hMutexHandle);
}
Exemplo n.º 10
0
/*!
******************************************************************************

 @Function                POOL_ResClone

******************************************************************************/
IMG_RESULT POOL_ResClone(
    IMG_HANDLE    hPoolResHandle,
    IMG_HANDLE *  phClonePoolResHandle,
    IMG_VOID **   ppvParam
)
{
    POOL_sResource *  psResource = hPoolResHandle;
    POOL_sResPool *   psResPool;
    POOL_sResource *  psOrigResource = psResource;
    POOL_sResource *  psCloneResource;
    IMG_UINT32        ui32Result;

    IMG_ASSERT(gInitialised);
    IMG_ASSERT(psResource != IMG_NULL);

    if (!gInitialised ||
        psResource == IMG_NULL)
    {
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error_nolock;
    }

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

    psResPool = psResource->psResPool;
    IMG_ASSERT(psResPool != IMG_NULL);
    if(psResPool == IMG_NULL)
    {
        return IMG_ERROR_FATAL;
    }

    /* Lock the pool...*/
    SYSOSKM_LockMutex(psResPool->hMutexHandle);

    /* Set resource id...*/
    ui32Result = IDGEN_AllocId(psResPool->hIdGenHandle, (IMG_HANDLE)psCloneResource, &psCloneResource->ui32ResId);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error_alloc_id;
    }

    /* If this is a clone, set the original...*/
    if (psResource->bIsClone)
    {
        psOrigResource = psResource->psOrigResource;
    }
    IMG_ASSERT(psOrigResource->ui32RefCnt > 0);

    /* Setup the cloned resource...*/
    psCloneResource->bIsClone       = IMG_TRUE;
    psCloneResource->psResPool      = psResPool;
    psCloneResource->psOrigResource = psOrigResource;

    /* Add to clone list...*/
    LST_add(&psOrigResource->sCloneResList, psCloneResource);
    psOrigResource->ui32RefCnt++;

    /* If ppvParam is not IMG_NULL...*/
    if (ppvParam !=IMG_NULL)
    {
        /* If the size of the original vParam is 0...*/
        if (psOrigResource->ui32SizevParam == 0)
        {
            *ppvParam = IMG_NULL;
        }
        else
        {
            /* Allocate memory for a copy of the original vParam...*/
            *ppvParam = IMG_MALLOC(psOrigResource->ui32SizevParam);
            IMG_ASSERT(*ppvParam != IMG_NULL);
            if (*ppvParam == IMG_NULL)
            {
                ui32Result = IMG_ERROR_OUT_OF_MEMORY;
                goto error_copy_param;
            }
            IMG_MEMCPY(*ppvParam, psOrigResource->pvParam, psOrigResource->ui32SizevParam);
        }
    }

    /* Unlock the pool...*/
    SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

    /* Return the cloned resource...*/
    *phClonePoolResHandle = psCloneResource;

    /* Return IMG_SUCCESS...*/
    return IMG_SUCCESS;

    /* Error handling. */
error_copy_param:
    LST_remove(&psOrigResource->sCloneResList, psCloneResource);
    psOrigResource->ui32RefCnt--;
error_alloc_id:
    IMG_FREE(psCloneResource);

    /* Unlock the pool...*/
    SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

error_nolock:
    return ui32Result;
}
Exemplo n.º 11
0
/*!
******************************************************************************

 @Function                POOL_ResFree

******************************************************************************/
IMG_RESULT POOL_ResFree(
    IMG_HANDLE  hPoolResHandle
)
{
    POOL_sResource *  psResource = hPoolResHandle;
    POOL_sResPool *   psResPool;
    POOL_sResource *  psOrigResource;
    IMG_UINT32        ui32Result;

    IMG_ASSERT(gInitialised);
    IMG_ASSERT(psResource != IMG_NULL);

    if (!gInitialised ||
        psResource == IMG_NULL)
    {
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error_nolock;
    }

    psResPool = psResource->psResPool;

    /* Lock the pool...*/
    SYSOSKM_LockMutex(psResPool->hMutexHandle);

    /* If this is a clone...*/
    if (psResource->bIsClone)
    {
        /* Get access to the original...*/
        psOrigResource = psResource->psOrigResource;
        IMG_ASSERT(psOrigResource != IMG_NULL);
        IMG_ASSERT(!psOrigResource->bIsClone);

        /* Remove from the clone list...*/
        LST_remove(&psOrigResource->sCloneResList, psResource);

        /* Free resource id...*/
        ui32Result = IDGEN_FreeId(psResPool->hIdGenHandle, psResource->ui32ResId);
        IMG_ASSERT(ui32Result == IMG_SUCCESS);
        if (ui32Result != IMG_SUCCESS)
        {
            /* Unlock the pool...*/
            SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

            return ui32Result;
        }

        /* If we created a copy of the resources pvParam then free it...*/
        if (psResource->pvParam != IMG_NULL)
        {
            IMG_FREE(psResource->pvParam );
        }
        /* Free the clone resource structure...*/
        IMG_FREE(psResource);

        /* Set resource to be "freed" to the original...*/
        psResource = psOrigResource;
    }

    /* Update the reference count...*/
    IMG_ASSERT(psResource->ui32RefCnt != 0);
    psResource->ui32RefCnt--;

    /* If there are still outstanding references...*/
    if (psResource->ui32RefCnt != 0)
    {
        /* Unlock the pool...*/
        SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

        /* Return IMG_SUCCESS...*/
        return IMG_SUCCESS;
    }

    /* Remove the resource from the active list...*/
    LST_remove(&psResPool->sActResList, psResource);

    /* If free callback set...*/
    if (psResPool->pfnFree != IMG_NULL)
    {
        /* Add to active list...*/
        LST_add(&psResPool->sActResList, psResource);
        psResource->ui32RefCnt++;
    }
    else
    {
        /* Add to free list...*/
        LST_add(&psResPool->sFreeResList, psResource);
    }

    /* Unlock the pool...*/
    SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

    /* If free callback set...*/
    if (psResPool->pfnFree != IMG_NULL)
    {
        /* Call the free callback...*/
        psResPool->pfnFree(psResource->ui32ResId, psResource->pvParam);
    }

    /* Return IMG_SUCCESS...*/
    return IMG_SUCCESS;

error_nolock:
    return ui32Result;
}
Exemplo n.º 12
0
/*!
******************************************************************************

 @Function                POOL_ResDestroy

******************************************************************************/
IMG_RESULT POOL_ResDestroy(
    IMG_HANDLE  hPoolResHandle,
    IMG_BOOL    bForce
)
{
    POOL_sResource *  psResource = hPoolResHandle;
    POOL_sResPool *   psResPool;
    POOL_sResource *  psOrigResource;
    POOL_sResource *  psCloneResource;
    IMG_UINT32        ui32Result;

    IMG_ASSERT(gInitialised);
    IMG_ASSERT(psResource != IMG_NULL);

    if (!gInitialised ||
        psResource == IMG_NULL)
    {
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error_nolock;
    }

    psResPool = psResource->psResPool;

    /* Lock the pool...*/
    SYSOSKM_LockMutex(psResPool->hMutexHandle);

    /* If this is a clone...*/
    if (psResource->bIsClone)
    {
        IMG_ASSERT(0);        // We need to check this works.

        /* Get access to the original...*/
        psOrigResource = psResource->psOrigResource;
        IMG_ASSERT(psOrigResource != IMG_NULL);
        if (psOrigResource == IMG_NULL)
        {
            ui32Result = IMG_ERROR_UNEXPECTED_STATE;
            goto error;
        }
		
        IMG_ASSERT(!psOrigResource->bIsClone);
        if (psOrigResource->bIsClone)
        {
            ui32Result = IMG_ERROR_UNEXPECTED_STATE;
            goto error;
        }

        /* Remove from the clone list...*/
        LST_remove(&psOrigResource->sCloneResList, psResource);

        /* Free resource id...*/
        ui32Result = IDGEN_FreeId(psResPool->hIdGenHandle, psResource->ui32ResId);
        IMG_ASSERT(ui32Result == IMG_SUCCESS);
        if (ui32Result != IMG_SUCCESS)
        {
            /* Unlock the pool...*/
            SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

            return ui32Result;
        }

        /* If we created a copy of the resources pvParam then free it...*/
        if (psResource->pvParam != IMG_NULL)
        {
            IMG_FREE(psResource->pvParam );
        }
        /* Free the clone resource structure...*/
        IMG_FREE(psResource);

        /* Set resource to be "freed" to the original...*/
        psResource = psOrigResource;
    }

    /* If there are still outstanding references...*/
    if ( (!bForce) && (psResource->ui32RefCnt != 0) )
    {
        IMG_ASSERT(0);      // We may need to mark the resource and destroy it when
                            // there are no outstanding references
        /* Unlock the pool...*/
        SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

        /* Return IMG_SUCCESS...*/
        return IMG_SUCCESS;
    }

    /* Check clone list is empty...*/
    psCloneResource = LST_first(&psResource->sCloneResList);
    IMG_ASSERT(psCloneResource == IMG_NULL);

    /* Has the resource outstanding references...*/
    if (psResource->ui32RefCnt != 0)
    {
        /* Remove the resource from the active list...*/
        LST_remove(&psResPool->sActResList, psResource);
    }
    else
    {
        /* Remove the resource from the free list...*/
        LST_remove(&psResPool->sFreeResList, psResource);
    }

    /* Free resource id...*/
    ui32Result = IDGEN_FreeId(psResPool->hIdGenHandle, psResource->ui32ResId);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        /* Unlock the pool...*/
        SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

        return ui32Result;
    }

    /* Call the resource destructor...*/
    psResource->pfnDestructor(psResource->pvParam);
    IMG_FREE(psResource);

    /* Unlock the pool...*/
    SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

    /* Return IMG_SUCCESS...*/
    return IMG_SUCCESS;

error:
	SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

error_nolock:
    return ui32Result;
}
Exemplo n.º 13
0
/*!
******************************************************************************

 @Function                POOL_ResRegister

******************************************************************************/
IMG_RESULT POOL_ResRegister(
    IMG_HANDLE          hPoolHandle,
    POOL_pfnDestructor  pfnDestructor,
    IMG_VOID *          pvParam,
    IMG_UINT32          ui32SizevParam,
    IMG_BOOL            bAlloc,
    IMG_UINT32 *        pui32ResId,
    IMG_HANDLE *        phPoolResHandle
)
{
    POOL_sResPool *   psResPool = hPoolHandle;
    POOL_sResource *  psResource;
    IMG_UINT32        ui32Result;

    IMG_ASSERT(gInitialised);
    IMG_ASSERT(psResPool != IMG_NULL);

    if (!gInitialised ||
        psResPool == IMG_NULL)
    {
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error_nolock;
    }

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

    /* Setup the resource...*/
    psResource->pfnDestructor  = pfnDestructor;
    psResource->pvParam        = pvParam;
    psResource->ui32SizevParam = ui32SizevParam;
    psResource->psResPool      = psResPool;
    LST_init(&psResource->sCloneResList);

    /* Lock the pool...*/
    SYSOSKM_LockMutex(psResPool->hMutexHandle);

    /* Set resource id...*/
    ui32Result = IDGEN_AllocId(psResPool->hIdGenHandle, (IMG_HANDLE)psResource, &psResource->ui32ResId);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        IMG_FREE(psResource);
        /* Unlock the pool...*/
        SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

        return ui32Result;
    }

    /* If allocated or free callback not set...*/
    if ( (bAlloc) || (psResPool->pfnFree != IMG_NULL) )
    {
        /* Add to active list...*/
        LST_add(&psResPool->sActResList, psResource);
        psResource->ui32RefCnt++;
    }
    else
    {
        /* Add to free list...*/
        LST_add(&psResPool->sFreeResList, psResource);
    }

    /* Return the resource id...*/
    if (pui32ResId != IMG_NULL)
    {
        *pui32ResId = psResource->ui32ResId;
    }

    /* Return the handle to the resource...*/
    if (phPoolResHandle != IMG_NULL)
    {
        *phPoolResHandle = psResource;
    }

    /* Unlock the pool...*/
    SYSOSKM_UnlockMutex(psResPool->hMutexHandle);


    /* If free callback set...*/
    if (psResPool->pfnFree != IMG_NULL)
    {
        /* Call the free callback...*/
        psResPool->pfnFree(psResource->ui32ResId, psResource->pvParam);
    }

    /* Return IMG_SUCCESS...*/
    return IMG_SUCCESS;

error_nolock:
    return ui32Result;
}
Exemplo n.º 14
0
/*!
******************************************************************************

 @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;
}
Exemplo n.º 15
0
static void perflog_stop(struct seq_file *s, void *buffer)
{
    //release file
    SYSOSKM_UnlockMutex(gsPerfFile.hMutexHandle);
}
Exemplo n.º 16
0
/*!
******************************************************************************

 @Function				RMAN_RegisterResource

******************************************************************************/
IMG_RESULT RMAN_RegisterResource(
    IMG_HANDLE				hResBHandle,
    IMG_UINT32				ui32TypeId,
    RMAN_pfnFree			pfnFree,
    IMG_VOID *              pvParam,
    IMG_HANDLE *			phResHandle,
    IMG_UINT32 *			pui32ResId
)
{
    RMAN_sBucket *				psBucket = (RMAN_sBucket *) hResBHandle;
    RMAN_sResource *			psResource;
    IMG_RESULT                  i32Result;

    IMG_ASSERT(gInitialised);
    IMG_ASSERT(ui32TypeId		!= RMAN_ALL_TYPES);

    IMG_ASSERT(hResBHandle != IMG_NULL);
    if (hResBHandle == IMG_NULL)
    {
        return IMG_ERROR_GENERIC_FAILURE;
    }

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

    /* Fill in the resource structure...*/
    psResource->psBucket		= psBucket;
    psResource->ui32TypeId		= ui32TypeId;
    psResource->pfnFree			= pfnFree;
    psResource->pvParam         = pvParam;

    /* Allocate resource Id...*/
    SYSOSKM_LockMutex(globalMutext);
    i32Result = IDGEN_AllocId(psBucket->hIdGenerator, psResource, &psResource->ui32ResId);
    SYSOSKM_UnlockMutex(globalMutext);
    if(i32Result != IMG_SUCCESS)
    {
        IMG_ASSERT(!"failed to allocate RMAN id");
        return i32Result;
    }
    IMG_ASSERT(psResource->ui32ResId <= RMAN_CRESID_MAX_RES_ID);

    // add this resource to the bucket
    SYSOSKM_DisableInt();
    DQ_addTail(&psBucket->sResList, psResource);

    /* Update count of resources...*/
    psBucket->ui32ResCnt++;
    SYSOSKM_EnableInt();

    /* If resource handle required...*/
    if (phResHandle != IMG_NULL)
    {
        *phResHandle = psResource;
    }

    /* If resource id required...*/
    if (pui32ResId != IMG_NULL)
    {
        *pui32ResId = RMAN_GetResourceId(psResource);
    }

    /* Return success...*/
    return IMG_SUCCESS;
}