Ejemplo n.º 1
0
/*****************************************************************************
 Function : osMemFreeNode
 Description : free the node from memory & if there are free node beside, merger them.
                    at last update "pstListHead' which saved all free node control head
 Input       : pstNode -- the node which need be freed
                  pPool --Pointer to memory pool
 Output      : None
 Return      : None
*****************************************************************************/
INLINE VOID osMemFreeNode(LOS_MEM_DYN_NODE *pstNode, VOID *pPool)
{
    LOS_MEM_DYN_NODE *pstNextNode = (LOS_MEM_DYN_NODE *)NULL;
    LOS_DL_LIST *pstListHead = (LOS_DL_LIST *)NULL;

    OS_MEM_REDUCE_USED(OS_MEM_NODE_GET_SIZE(pstNode->uwSizeAndFlag));
    pstNode->uwSizeAndFlag = OS_MEM_NODE_GET_SIZE(pstNode->uwSizeAndFlag);
    if ((pstNode->pstPreNode != NULL) &&
        (!OS_MEM_NODE_GET_USED_FLAG(pstNode->pstPreNode->uwSizeAndFlag)))
    {
        LOS_MEM_DYN_NODE *pstPreNode = pstNode->pstPreNode;
        osMemMergeNode(pstNode);
        pstNextNode = OS_MEM_NEXT_NODE(pstPreNode);
        if (!OS_MEM_NODE_GET_USED_FLAG(pstNextNode->uwSizeAndFlag))
        {
            LOS_ListDelete(&(pstNextNode->stFreeNodeInfo));
            osMemMergeNode(pstNextNode);
        }

        LOS_ListDelete(&(pstPreNode->stFreeNodeInfo));
        pstListHead = OS_MEM_HEAD(pPool, pstPreNode->uwSizeAndFlag);
        if (NULL == pstListHead)
        {
            PRINT_ERR("%s %d\n", __FUNCTION__, __LINE__);
            return;
        }

        LOS_ListAdd(pstListHead,&(pstPreNode->stFreeNodeInfo));
    }
    else
    {
        pstNextNode = OS_MEM_NEXT_NODE(pstNode);
        if (!OS_MEM_NODE_GET_USED_FLAG(pstNextNode->uwSizeAndFlag))
        {
            LOS_ListDelete(&(pstNextNode->stFreeNodeInfo));
            osMemMergeNode(pstNextNode);
        }

        pstListHead = OS_MEM_HEAD(pPool, pstNode->uwSizeAndFlag);
        if (NULL == pstListHead)
        {
            PRINT_ERR("%s %d\n", __FUNCTION__, __LINE__);
            return;
        }

        LOS_ListAdd(pstListHead,&(pstNode->stFreeNodeInfo));
    }
}
Ejemplo n.º 2
0
/*****************************************************************************
 Function : osMemSpitNode
 Description : spit new node from pstAllocNode, and merge remainder mem if necessary
 Input       : pPool --Pointer to memory pool
                  pstAllocNode --the source node which new node be spit from to.
                                        After pick up it's node info, change to point the new node
                  uwAllocSize -- the size of new node
 Output      : pstAllocNode -- save new node addr
 Return      : None
*****************************************************************************/
INLINE VOID osMemSpitNode(VOID *pPool,
                            LOS_MEM_DYN_NODE *pstAllocNode, UINT32 uwAllocSize)
{
    LOS_MEM_DYN_NODE *pstNewFreeNode = (LOS_MEM_DYN_NODE *)NULL;
    LOS_MEM_DYN_NODE *pstNextNode = (LOS_MEM_DYN_NODE *)NULL;
    LOS_DL_LIST *pstListHead = (LOS_DL_LIST *)NULL;

    pstNewFreeNode = (LOS_MEM_DYN_NODE *)((UINT8 *)pstAllocNode + uwAllocSize);
    pstNewFreeNode->pstPreNode = pstAllocNode;
    pstNewFreeNode->uwSizeAndFlag = pstAllocNode->uwSizeAndFlag - uwAllocSize;
    pstAllocNode->uwSizeAndFlag = uwAllocSize;
    pstNextNode = OS_MEM_NEXT_NODE(pstNewFreeNode);
    pstNextNode->pstPreNode = pstNewFreeNode;
    if (!OS_MEM_NODE_GET_USED_FLAG(pstNextNode->uwSizeAndFlag))
    {
        LOS_ListDelete(&(pstNextNode->stFreeNodeInfo));
        osMemMergeNode(pstNextNode);
    }

    pstListHead = OS_MEM_HEAD(pPool, pstNewFreeNode->uwSizeAndFlag);
    if (NULL == pstListHead)
    {
        PRINT_ERR("%s %d\n", __FUNCTION__, __LINE__);
        return;
    }

    LOS_ListAdd(pstListHead,&(pstNewFreeNode->stFreeNodeInfo));
}
Ejemplo n.º 3
0
/*****************************************************************************
 Function     : LOS_MuxDelete
 Description  : Delete a mutex,
 Input        : uwMuxHandle------Mutex operation handle
 Output       : None
 Return       : LOS_OK on success ,or error code on failure
 *****************************************************************************/
LITE_OS_SEC_TEXT_INIT UINT32 LOS_MuxDelete(UINT32 uwMuxHandle)
{
    UINT32    uwIntSave;
    MUX_CB_S *pstMuxDeleted;
    UINT32   uwErrNo;
    UINT32   uwErrLine;

    if (uwMuxHandle >= (UINT32)LOSCFG_BASE_IPC_MUX_LIMIT)
    {
        OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_INVALID);
    }

    pstMuxDeleted = GET_MUX(uwMuxHandle);
    uwIntSave = LOS_IntLock();
    if (OS_MUX_UNUSED == pstMuxDeleted->ucMuxStat)
    {
        LOS_IntRestore(uwIntSave);
        OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_INVALID);
    }

    if (!LOS_ListEmpty(&pstMuxDeleted->stMuxList) || pstMuxDeleted->usMuxCount)
    {
        LOS_IntRestore(uwIntSave);
        OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_PENDED);
    }

    LOS_ListAdd(&g_stUnusedMuxList, &pstMuxDeleted->stMuxList);
    pstMuxDeleted->ucMuxStat = OS_MUX_UNUSED;

    LOS_IntRestore(uwIntSave);

    return LOS_OK;
ErrHandler:
    OS_RETURN_ERROR_P2(uwErrLine, uwErrNo);
}