Beispiel #1
0
osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id)
{
    PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
    UINTPTR uwIntSave;
    osStatus_t uwRet;

    uwIntSave = LOS_IntLock();
    if (LOS_EventDestory(pstEventCB) == LOS_OK)
    {
        uwRet = osOK;
    }
    else
    {
        uwRet = osErrorParameter;
    }
    LOS_IntRestore(uwIntSave);

    if (LOS_MemFree(m_aucSysMem0, (void *)pstEventCB) == LOS_OK)
    {
        uwRet = osOK;
    }
    else
    {
        uwRet = osErrorParameter;
    }

    return uwRet;
}
Beispiel #2
0
/*****************************************************************************
 Function : LOS_MemRealloc
 Description : reAlloc memory node
 Input       : pPool    --- Pointer to memory pool
                  pPtr  --- pointer to memory node which will be realloced
                 uwSize  --- the size of new node
 Output      : None
 Return      : Pointer to allocated memory
*****************************************************************************/
LITE_OS_SEC_TEXT_MINOR VOID *LOS_MemRealloc (VOID *pPool,  VOID *pPtr, UINT32 uwSize)
{
    UINTPTR uvIntSave;
    UINT32 uwGapSize = 0;
    VOID *pNewPtr = NULL;

    uvIntSave = LOS_IntLock();

    do
    {
        LOS_MEM_DYN_NODE *pstNode = (LOS_MEM_DYN_NODE *)NULL;
        UINT32 uwRet;
        UINT32 uwAllocSize;
        UINT32 uwNodeSize;
        LOS_MEM_DYN_NODE *pstNextNode = (LOS_MEM_DYN_NODE *)NULL;

        if (pPtr == NULL)
        {
            pNewPtr = LOS_MemAlloc((VOID *)pPool, (UINT32)uwSize);
            break;
        }

        if (uwSize == 0)
        {
            if (LOS_MemFree((VOID *)pPool, (VOID *)pPtr) != LOS_OK)
                 PRINT_ERR("%s, %d\n", __FUNCTION__, __LINE__);
            break;
        }

        uwGapSize = *((UINT32 *)((UINT32)pPtr - 4));
        if (OS_MEM_NODE_GET_ALIGNED_FLAG(uwGapSize))
        {
            uwGapSize = OS_MEM_NODE_GET_ALIGNED_GAPSIZE(uwGapSize);
            pPtr = (VOID *)((UINT32)pPtr - uwGapSize);
        }
        pstNode = (LOS_MEM_DYN_NODE *)((UINT32)pPtr - OS_MEM_NODE_HEAD_SIZE);
        uwRet = osMemCheckUsedNode(pPool, pstNode);
        if (uwRet != LOS_OK)
        {
            break;
        }

        uwAllocSize = OS_MEM_ALIGN(uwSize + OS_MEM_NODE_HEAD_SIZE, OS_MEM_ALIGN_SIZE);
        uwNodeSize = OS_MEM_NODE_GET_SIZE(pstNode->uwSizeAndFlag);
        if (uwNodeSize >= uwAllocSize)
        {
            osMemReAllocSmaller(pPool, uwAllocSize, pstNode, uwNodeSize);
            pNewPtr = pPtr;
            break;
        }

        pstNextNode = OS_MEM_NEXT_NODE(pstNode);
        if ((!OS_MEM_NODE_GET_USED_FLAG(pstNextNode->uwSizeAndFlag)) &&
            ((pstNextNode->uwSizeAndFlag + uwNodeSize) >= uwAllocSize))
        {
            osMemMergeNodeForReAllocBigger(pPool, uwAllocSize, pstNode, uwNodeSize, pstNextNode);
            pNewPtr = pPtr;
            break;
        }

        pNewPtr = osMemAllocWithCheck(pPool, uwSize);
        if (pNewPtr != NULL)
        {
            (VOID)memcpy(pNewPtr, pPtr, uwNodeSize - OS_MEM_NODE_HEAD_SIZE);
            osMemFreeNode(pstNode, pPool);
        }

    } while (0);

    LOS_IntRestore(uvIntSave);
    return pNewPtr;
}