/***************************************************************************** Funtion : osMuxInit, Description : Initializes the mutex, Input : None Output : None Return : LOS_OK on success ,or error code on failure *****************************************************************************/ LITE_OS_SEC_TEXT_INIT UINT32 osMuxInit(VOID) { MUX_CB_S *pstMuxNode; UINT32 uwIndex; LOS_ListInit(&g_stUnusedMuxList); if (LOSCFG_BASE_IPC_MUX_LIMIT == 0) /*lint !e506*/ { return LOS_ERRNO_MUX_MAXNUM_ZERO; } g_pstAllMux = (MUX_CB_S *)LOS_MemAlloc(m_aucSysMem0, (LOSCFG_BASE_IPC_MUX_LIMIT * sizeof(MUX_CB_S))); if (NULL == g_pstAllMux) { return LOS_ERRNO_MUX_NO_MEMORY; } for (uwIndex = 0; uwIndex < LOSCFG_BASE_IPC_MUX_LIMIT; uwIndex++) { pstMuxNode = ((MUX_CB_S *)g_pstAllMux) + uwIndex; pstMuxNode->ucMuxID = uwIndex; pstMuxNode->ucMuxStat = OS_MUX_UNUSED; LOS_ListTailInsert(&g_stUnusedMuxList, &pstMuxNode->stMuxList); } return LOS_OK; }
osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr) { PEVENT_CB_S pstEventCB = NULL; UINT32 uwRet; UNUSED(attr); if (OS_INT_ACTIVE) { return (osEventFlagsId_t)NULL; } pstEventCB = (PEVENT_CB_S)LOS_MemAlloc(m_aucSysMem0, sizeof(EVENT_CB_S)); if(pstEventCB == NULL ) { return (osEventFlagsId_t)NULL; } uwRet = LOS_EventInit(pstEventCB); if (uwRet == LOS_ERRNO_EVENT_PTR_NULL) { return (osEventFlagsId_t)NULL; } else { return (osEventFlagsId_t)pstEventCB; } }
/***************************************************************************** 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; }