int etherMultiDel ( LIST *pList, /* pointer to list of multicast addresses */ char* pAddress /* address you want to add to list */ ) { ETHER_MULTI* pCurr; /* * Look up the address in our list. */ for (pCurr = (ETHER_MULTI *)lstFirst(pList); pCurr != NULL && (bcmp(pCurr->addr, pAddress, 6) != 0); pCurr = (ETHER_MULTI *)lstNext(&pCurr->node)); if (pCurr == NULL) { return (ENXIO); } if (--pCurr->refcount != 0) { /* * Still some claims to this record. */ return (0); } /* * No remaining claims to this record; unlink and free it. */ lstDelete(pList, &pCurr->node); KHEAP_FREE((char *)pCurr); /* * Return ENETRESET to inform the driver that the list has changed * and its reception filter should be adjusted accordingly. */ return (ENETRESET); }
void etherOutputHookDelete ( FUNCPTR outputHook ) { HOOK_ENTRY *pHookEnt; extern LIST outputHookList; NODE index; for (pHookEnt = (HOOK_ENTRY *)lstFirst(&outputHookList); pHookEnt != NULL; pHookEnt = (HOOK_ENTRY *)lstNext(&index)) { index = pHookEnt->node; if (pHookEnt->routine == outputHook) { lstDelete(&outputHookList, &pHookEnt->node); free(pHookEnt); } } if (lstCount(&outputHookList) <= 0) { etherOutputHookRtn = NULL; lstFree(&outputHookList); } }
STATUS hostTblSearchByAddr ( int addr, /* inet address of host */ char *name /* buffer to hold name */ ) { HOSTENTRY *pHostEntry; struct in_addr netAddr; STATUS status = ERROR; int n; netAddr.s_addr = addr; semTake (hostListSem, WAIT_FOREVER); /* search for internet address */ for (pHostEntry = (HOSTENTRY *)lstFirst (&hostList); pHostEntry != NULL; pHostEntry = (HOSTENTRY *)lstNext (&pHostEntry->node)) { if (pHostEntry->netAddr.s_addr == netAddr.s_addr) { n = strlen (pHostEntry->hostName.name); strncpy (name, pHostEntry->hostName.name, min (n + 1 , MAXHOSTNAMELEN +1)); status = OK; break; } } semGive (hostListSem); return (status); }
BST_VOID BST_CTaskSchdler::TimerExpired( BST_OS_TIMERID_T ulId, BST_VOID *pvPara) { BST_CORE_PTASK_NODE_STRU *pstPtaskNode; BST_CORE_PTASK_NODE_STRU *pstPtaskNodeNext; if ( !BST_OS_IsTimerValid (m_ulTimerId) ) { BST_RLS_LOG1( "BST_CTaskSchdler::TimerExpired m_ulTimerId=%u is invalid", m_ulTimerId ); return; } if ( ulId != m_ulTimerId ) { BST_RLS_LOG2( "BST_CTaskSchdler::TimerExpired ulId=%u,m_ulTimerId=%u", ulId, m_ulTimerId ); return; } /* * 如果没有任务,则直接返回,不做任何操作 */ if ( 0 == lstCount( &g_stPTaskList ) ) { BST_RLS_LOG( "BST_CTaskSchdler::TimerExpired g_stPTaskList count=0" ); return; } /* * 更新系统TICK值 */ m_ulSystemTick += BST_TASK_SYS_TICKS; BST_DBG_LOG1 ( "BST_CTaskSchdler::TimerExpired Scheduler TimeOut, Tick=%d ", m_ulSystemTick ); /* * 遍历任务列表,获取任务并进行相应调度 */ for ( pstPtaskNode = ( BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = pstPtaskNodeNext ) { pstPtaskNodeNext = ( BST_CORE_PTASK_NODE_STRU *) lstNext((NODE *)pstPtaskNode); if ( BST_NULL_PTR == pstPtaskNode->pcTask ) { continue; } /* * 如果任务不为空,则根据状态进行调度 */ ScheduleTask ( pstPtaskNode->pcTask ); } /* * 再次启动系统TICK定时器 */ BST_OS_TimerStart ( m_ulTimerId, BST_TASK_SYS_BASE_TIMELEN ); }
void wdAddVxFromList(World* W, List L) { Node* it = lstFirst(&L); while(!nodeEnd(it)) { wdAddVertex(W, (Vertex*) nodeGetData(it)); it = nodeGetNext(it); } }
BST_UINT32 BST_CTaskSchdler::NearRrcTrig ( BST_UINT32 const ulSysTimerRemainMs ) { BST_CORE_PTASK_NODE_STRU *pstPtaskNode; BST_UINT32 ulNextSysTick; BST_UINT32 ulNextLongCycle; ulNextLongCycle = 0; ulNextSysTick = m_ulSystemTick + BST_TASK_SYS_TICKS; /* * 遍历任务列表,找出所有有效任务 */ for( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode) ) { if( BST_NULL_PTR == pstPtaskNode->pcTask ) { continue; } if( 0 == pstPtaskNode->pcTask->m_ulCycle ) { continue; } if( BST_TRUE == pstPtaskNode->pcTask->IsBusy () ) { continue; } if( BST_TASK_STATE_START != pstPtaskNode->pcTask->GetState () ) { continue; } /* * 查看是否有任务周期与Tick整除项,代码周期到来 */ if( 0 == ( ulNextSysTick % pstPtaskNode->pcTask->m_ulCycle ) ) { if( pstPtaskNode->pcTask->m_ulCycle > ulNextLongCycle ) { ulNextLongCycle = pstPtaskNode->pcTask->m_ulCycle; } } } /* * 获取当前系统周期,并取比例,如果剩余时间低于该值,则说明足够靠近 */ ulNextLongCycle = BST_CORE_GetCycleToMs( ulNextLongCycle ); if( BST_TASK_IsNearEnough( ulSysTimerRemainMs, ulNextLongCycle ) ) { BST_RLS_LOG("BST_CTaskSchdler::NearRrcTrig Closing To RRC Enough, Periodic Runing after 200Ms"); return BST_TASK_RRC_SEND_TIMER; } else { return ulSysTimerRemainMs; } }
void wdResolveElastic(World* W) { Node* it = lstFirst(&W->Elastics); while(!nodeEnd(it)) { elResolve((Elastic*) nodeGetData(it)); it = nodeGetNext(it); } }
void wdResolveRigid(World* W) { Node* it = lstFirst(&W->Rigids); /* Parcoure les contraintes orphelines */ while(!nodeEnd(it)) { rdResolve( (Rigid*) nodeGetData(it)); it = nodeGetNext(it); } /* Parcoure les Polygons */ it = lstFirst(&W->Polygons); while(!nodeEnd(it)) { polyResolve((Polygon*) nodeGetData(it)); it = nodeGetNext(it); } }
void wdUpdateGrid(World *W, Bool Force) { Node* it = lstFirst(&W->Polygons); while(!nodeEnd(it)) { if (Force || !polyIsFixed((Polygon*)nodeGetData(it))) gridUpdatePolygonPositionByBB(&W->CollisionGrid, (Polygon*)nodeGetData(it)); it=nodeGetNext(it); } }
BST_BOOL BST_CTaskSchdler::TryTaskExist ( BST_VOID ) { BST_UINT32 ulNextTick; BST_TASK_STATE_ENUM_UINT8 enTaskState; BST_SRV_CTaskMng *pcTaskManager; BST_CORE_PTASK_NODE_STRU *pstPtaskNode; ulNextTick = 0; pcTaskManager = BST_SRV_CTaskMng::GetInstance (); BST_ASSERT_NULL_RTN( pcTaskManager, BST_FALSE ); /* * 在当前系统值加一个TICK单位,获得下一时刻TICK值 */ ulNextTick = m_ulSystemTick + BST_TASK_SYS_TICKS; for ( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode ) ) { if ( BST_NULL_PTR == pstPtaskNode->pcTask ) { continue; } /* * 如果任务没有执行完成,处于繁忙状态,则立即返回 */ if ( BST_TRUE == pstPtaskNode->pcTask->IsBusy () ) { continue; } /* * 如果TICK值能够被任务周期整除,说明到了该任务周期 */ if ( 0 == ( ulNextTick % pstPtaskNode->pcTask->m_ulCycle ) ) { enTaskState = pstPtaskNode->pcTask->GetState (); if ( BST_TASK_STATE_START == enTaskState ) { return BST_TRUE; } else { continue; } } else { continue; } } return BST_FALSE; }
void objFree(Object* Obj) { Node* N; while(lstCount(&Obj->CoordTex) > 0) { N = lstFirst(&Obj->CoordTex); delVec2((Vec2*) nodeGetData(N)); lstRem(&Obj->CoordTex, N); } lstFree(&Obj->CoordTex); // Peu utile Obj->Shape = NULL; Obj->Tex = 0; }
/*lint -e429*/ BST_VOID BST_CTaskSchdler::Attach ( BST_CORE_CPTask *pC_PTask ) { BST_CORE_PTASK_NODE_STRU *pstPtaskNode; if ( !BST_OS_IsTimerValid (m_ulTimerId) ) { BST_RLS_LOG1( "BST_CTaskSchdler::Attach m_ulTimerId=%u is invalid", m_ulTimerId ); return; } if ( BST_NULL_PTR == pC_PTask ) { BST_RLS_LOG( "BST_CTaskSchdler::Attach pC_PTask=NULL" ); return; } for ( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode) ) { if( pstPtaskNode->pcTask == pC_PTask ) { return; } } /* * 申请链表节点资源,用于存储任务 */ pstPtaskNode = ( BST_CORE_PTASK_NODE_STRU *)BST_OS_MALLOC ( BST_OS_SIZEOF( BST_CORE_PTASK_NODE_STRU ) ); if( BST_NULL_PTR == pstPtaskNode ) { BST_RLS_LOG( "BST_CTaskSchdler::Attach pstPtaskNode=NULL" ); return; } /* * 初始化任务数据,添加如任务列表 */ pC_PTask->m_ulSuspCounter = 0; pstPtaskNode->pcTask = pC_PTask; lstAdd( &g_stPTaskList, (NODE *)pstPtaskNode ); /* * 如果此时系统TICK定时已经关闭,且PS域服务状态正常,那么需要再次启动定时 */ if( BST_TRUE == BST_OS_TimerIsStop( m_ulTimerId ) ) { m_ulSystemTick = 0; BST_OS_TimerStart ( m_ulTimerId, BST_TASK_SYS_BASE_TIMELEN ); BST_DBG_LOG1( "BST_CTaskSchdler::Attach Start Scheduler Timer:%u", BST_TASK_SYS_BASE_TIMELEN ); } }
Object* cpyObject(Object* O) { List CT; lstInit(&CT); Node* it = lstFirst(&O->CoordTex); while(!nodeEnd(it)) { Vec2* CoordTex = newVec2(); vec2Cp(CoordTex, *((Vec2*) nodeGetData(it))); lstAdd(&CT, CoordTex); it = nodeGetNext(it); } return newObject(cpyPolygon(O->Shape), O->Tex, CT); }
void wdResetGrid(World* W) { gridFree(&W->CollisionGrid); float CellSize=128.f; gridInit(&W->CollisionGrid, W->Width/CellSize+1, W->Height/CellSize+1); gridSetCellSize(&W->CollisionGrid, CellSize); Node* it = lstFirst(&W->Polygons); while(!nodeEnd(it)) { gridAddPolygonByBB(&W->CollisionGrid, (Polygon*)nodeGetData(it)); it=nodeGetNext(it); } }
OM_BST_APP_INFO_STRU *BST_SYS_MntnSrchAppByPort( BST_UINT16 usLocalPortNumber ) { BST_SYS_MNTN_APP_NODE_STRU *pstAppNode; /* 查找链表中是否已经存在该Port信息 */ for ( pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstFirst(BST_SYS_MNTN_GetAppListHead()); pstAppNode != BST_NULL_PTR; pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstNext( (NODE *)pstAppNode ) ) { if ( usLocalPortNumber == pstAppNode->stAppInfo.usLocalPort ) { return &pstAppNode->stAppInfo; } } return BST_NULL_PTR; }
Polygon* wdGetNearestPoly(World* W, float X, float Y) { Polygon *tmpPoly; List* LExtracted = gridGetPositionList(&W->CollisionGrid, X, Y); Node* it = lstFirst(LExtracted); while(!nodeEnd(it)) { tmpPoly = (Polygon*) nodeGetData(it); if (polyIsInside(tmpPoly, vec2(X, Y))) return tmpPoly; it = nodeGetNext(it); } return NULL; }
void *lstGoto( HLST hLst, long nIndex ) { long n = 0; if ( !hLst ) return NULL; lstFirst( hLst ); while ( (n < nIndex) && (!lstEOL( hLst )) ) { n++; lstNext( hLst ); } return hLst->hCurrent; }
LOCAL BOOL nptEtherInputHookRtn ( void * pCallBackId, /* Sent down in muxTkBind(); same as pSpare as in muxBind() */ long type, /* SNARF */ M_BLK_ID pMblk, /* Received frame (with link-level header). */ void * pSpareData /* Extra protocol data */ ) { HOOK_ENTRY * pHookEnt = (HOOK_ENTRY*) pCallBackId; char devName[32]; char packetData [ETHERMTU + SIZEOF_ETHERHEADER]; struct ifnet fakeIF; extern LIST inputHookList; int flags; int len; END_OBJ* pEnd=PCOOKIE_TO_ENDOBJ(pHookEnt->pCookie); int ifHdrLen=0; bzero ( (char *)&fakeIF, sizeof (fakeIF)); fakeIF.if_name = &devName[0]; strcpy (fakeIF.if_name, pEnd->devObject.name); fakeIF.if_unit = pEnd->devObject.unit; muxIoctl (pHookEnt->pCookie, EIOCGFLAGS, (caddr_t)&flags); fakeIF.if_flags = flags; /* Get the Link Level header length . */ if (muxIoctl (pHookEnt->pCookie, EIOCGHDRLEN, (caddr_t)&ifHdrLen) != OK) fakeIF.if_hdrlen = 0; else fakeIF.if_hdrlen = (UCHAR)ifHdrLen; len = netMblkToBufCopy(pMblk, (char *)packetData, NULL); for (pHookEnt = (HOOK_ENTRY *)lstFirst (&inputHookList); pHookEnt != NULL; pHookEnt = (HOOK_ENTRY *)lstNext (&pHookEnt->node)) { if ( (* pHookEnt->routine) (&fakeIF, packetData, len)) { netMblkClChainFree (pMblk); /* hook has consumed the packet */ return (TRUE); } } return (FALSE); }
void ReSchedule(Position itExist) { Position it, itPrev; time_node *pTemp, *timeVal; lstLock(g_timer); itPrev = lstHeader(g_timer); timeVal = (time_node*)lstRetrieve(itExist); for(it = lstFirst(g_timer); it != NULL; itPrev = it, it = lstAdvance(it)) { pTemp = (time_node*)lstRetrieve(it); if(pTemp->ulNextTime > timeVal->ulNextTime) break; } lstInsertPos(g_timer, itPrev, itExist); lstUnLock(g_timer); }
int hostTblSearchByName ( char *name /* name of host */ ) { HOSTNAME *pHostName; HOSTENTRY *pHostEntry; int retAddr = ERROR; semTake (hostListSem, WAIT_FOREVER); for (pHostEntry = (HOSTENTRY *)lstFirst (&hostList); pHostEntry != NULL; pHostEntry = (HOSTENTRY *)lstNext (&pHostEntry->node)) { /* check official name */ if (strcmp (pHostEntry->hostName.name, name) == 0) { retAddr = (int)pHostEntry->netAddr.s_addr; break; } /* check aliases */ for (pHostName = pHostEntry->hostName.link; pHostName != NULL; pHostName = pHostName->link) { if (strcmp (pHostName->name, name) == 0) { retAddr = (int)pHostEntry->netAddr.s_addr; /* force termination of outer loop */ pHostEntry = (HOSTENTRY *)lstLast (&hostList); break; } } } semGive (hostListSem); return (retAddr); }
OM_BST_APP_INFO_STRU *BST_SYS_MntnSrchAppByTask( BST_UINT16 usType, BST_UINT16 usTaskId ) { BST_SYS_MNTN_APP_NODE_STRU *pstAppNode; /* 查找链表中是否已经存在该Task信息 */ for ( pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstFirst(BST_SYS_MNTN_GetAppListHead()); pstAppNode != BST_NULL_PTR; pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstNext( (NODE *)pstAppNode ) ) { if ( ( usTaskId == pstAppNode->stAppInfo.usTaskId ) && ( usType == pstAppNode->stAppInfo.usAppType ) ) { return &pstAppNode->stAppInfo; } } return BST_NULL_PTR; }
Polygon* wdFindPolygon(World *W, Vertex* V) { Node* it; Polygon* P; it = lstFirst(&W->Polygons); while(!nodeEnd(it)) { P = (Polygon*)nodeGetData(it); unsigned int vxnb = polyGetVxCount(P), i; for (i=0; i<vxnb; i++) { if (polyGetVertex(P, i) == V) return P; } it = nodeGetNext(it); } return NULL; }
LOCAL BOOL etherOutputHook ( struct ifnet *pIf, char *buffer, int length ) { HOOK_ENTRY* pHookEnt; extern LIST outputHookList; for (pHookEnt = (HOOK_ENTRY *)lstFirst(&outputHookList); pHookEnt != NULL; pHookEnt = (HOOK_ENTRY *)lstNext(&pHookEnt->node)) { if ((* pHookEnt->routine) (pIf, buffer, length)) return (TRUE); } return (FALSE); }
/*lint -e438*/ BST_VOID BST_CTaskSchdler::Detach ( BST_CORE_CPTask *pC_PTask ) { BST_CORE_PTASK_NODE_STRU *pstPtaskNode; if ( !BST_OS_IsTimerValid (m_ulTimerId) ) { BST_RLS_LOG1( "BST_CTaskSchdler::Detach m_ulTimerId=%u is invalid", m_ulTimerId ); return; } if ( BST_NULL_PTR == pC_PTask ) { BST_RLS_LOG( "BST_CTaskSchdler::Detach pC_PTask=NULL" ); return; } /* * 遍历列表,找到pctask相符的任务,从链表删除,释放资源 */ for ( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode) ) { if( pstPtaskNode->pcTask != pC_PTask ) { continue; } lstDelete( &g_stPTaskList, (NODE *)pstPtaskNode ); BST_OS_FREE( pstPtaskNode ); break; } /* * 注销后,如果认为列表为空,则直接关闭定时器,不进行任何调度 */ if ( 0 == lstCount( &g_stPTaskList ) ) { BST_DBG_LOG( "BST_CTaskSchdler::Detach Stop Scheduler Timer" ); BST_OS_TimerStop ( m_ulTimerId ); } }
BST_VOID BST_SYS_MntnRemoveTask( BST_UINT16 usType, BST_UINT16 usTaskId ) { BST_SYS_MNTN_APP_NODE_STRU *pstAppNode; BST_OS_LOCKCNT_T tThreadLockCnt; if ( !BST_SYS_MNTN_IsMntnInited() ) { return; } tThreadLockCnt = BST_OS_ThreadLock(); /* 查找链表中是否已经存在该Task信息 */ for ( pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstFirst(BST_SYS_MNTN_GetAppListHead()); pstAppNode != BST_NULL_PTR; pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstNext( (NODE *)pstAppNode ) ) { if ( ( usTaskId == pstAppNode->stAppInfo.usTaskId ) && ( usType == pstAppNode->stAppInfo.usAppType ) ) { break; } } if ( BST_NULL_PTR == pstAppNode ) { BST_OS_ThreadUnLock( tThreadLockCnt ); return; } lstDelete( BST_SYS_MNTN_GetAppListHead(), (NODE *)pstAppNode ); BST_OS_FREE( pstAppNode ); BST_RLS_LOG3( "[Mntn] Remove Task: TypeId=, TaskId=, Total=", usType, usTaskId, BST_SYS_MNTN_GetAppNumber() ); BST_SYS_MntnChangedInd(); BST_OS_ThreadUnLock( tThreadLockCnt ); /*lint -e438*/ }
Vertex* wdGetNearest(World* W, float X, float Y) { if (lstEmpty(&W->Vertices)) return NULL; float Dist = powf(40.f, 2.f), tmpDist; Vertex* Nearest = NULL; Node* it = lstFirst(&W->Vertices); while(!nodeEnd(it)) { Vec2 VPos = vxGetPosition((Vertex*) nodeGetData(it)); Vec2 V = vec2(X - VPos.x, Y - VPos.y); tmpDist = vec2SqLength(V); if (tmpDist < Dist) { Dist = tmpDist; Nearest = (Vertex*) nodeGetData(it); } it = nodeGetNext(it); } return Nearest; }
BST_UINT32 BST_SYS_MntnBuildAgentInfoInd( OM_BST_APP_INFO_STRU *pstAgentInfo, const BST_UINT16 usAppNumber ) { BST_SYS_MNTN_APP_NODE_STRU *pstAppNode; BST_UINT16 usAppCounter; BST_OS_LOCKCNT_T tThreadLockCnt; if ( BST_NULL_PTR == pstAgentInfo ) { return BST_FALSE; } tThreadLockCnt = BST_OS_ThreadLock(); usAppCounter = 0; /* 查找链表中是否已经存在该Task信息 */ for ( pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstFirst(BST_SYS_MNTN_GetAppListHead()); pstAppNode != BST_NULL_PTR; pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstNext( (NODE *)pstAppNode ) ) { if ( ID_BST_OM_TASK_TYPE_MAIN == pstAppNode->stAppInfo.usAppType ) { continue; } BST_OS_MEMCPY( &pstAgentInfo[usAppCounter], &(pstAppNode->stAppInfo), BST_OS_SIZEOF(OM_BST_APP_INFO_STRU) ); usAppCounter++; if ( usAppCounter >= usAppNumber ) { break; } } BST_OS_ThreadUnLock( tThreadLockCnt ); return BST_TRUE; }
int etherMultiGet ( LIST* pList, /* pointer to list of multicast addresses */ MULTI_TABLE* pTable /* table into which to copy addresses */ ) { int count = 0; int len; ETHER_MULTI* pCurr; len = pTable->len; /* Save the passed in table length. */ pTable->len = 0; pCurr = (ETHER_MULTI *)lstFirst(pList); while (pCurr != NULL && count < len) { if (etherMultiDebug) { logMsg("%x:%x:%x:%x:%x:%x\n", pCurr->addr[0], pCurr->addr[1], pCurr->addr[2], pCurr->addr[3], pCurr->addr[4], pCurr->addr[5]); } bcopy(pCurr->addr, (char *)&pTable->pTable[count], 6); count+=6; pTable->len += 6; pCurr = (ETHER_MULTI *)lstNext(&pCurr->node); } return (OK); }
long ProcessTimer() { Position it, itHead, itFirst, itPrev; struct time_node* tvTimer; unsigned long ulNow; long ulRet = -1; List events = lstMakeEmpty(NULL); ulNow = get_tick_count(); if(g_timer == NULL) return -1; lstLock(g_timer); itFirst = it = lstFirst(g_timer); itPrev = itHead = lstHeader(g_timer); for(; it != NULL; itPrev = it, it = lstAdvance(it)) { tvTimer = (struct time_node*)lstRetrieve(it); if(ulNow >= tvTimer->ulNextTime) { if(tvTimer->nRemainCount > 0) tvTimer->nRemainCount--; if(tvTimer->nRemainCount != 0) tvTimer->ulNextTime += tvTimer->nInterval; } else { ulRet = tvTimer->ulNextTime - ulNow; break; } } //Now move the events from the timer list and insert into a temp list. if(itPrev != itHead){ itHead->Next = it; events->Next = itFirst; itPrev->Next = NULL; } lstUnLock(g_timer); itPrev = lstHeader(events); for(it = lstFirst(events); it != NULL; itPrev = it, it = lstAdvance(it)) { tvTimer = (struct time_node*)lstRetrieve(it); if(!tvTimer) continue; tvTimer->OnTimer(tvTimer->pPtr, tvTimer->ulID); if(tvTimer->nRemainCount != 0) { Position itTemp = lstRemovePos(g_timer, itPrev); it = itPrev; if(itTemp) ReSchedule(itTemp); }else { free(tvTimer); } } lstDeleteAll(events); return ulRet; }
BST_VOID BST_CTaskSchdler::UtranBlockInfoChgProc( BST_UINT32 *pulBlockInfo ) { BST_INT32 lTaskCnt; BST_UINT32 ulNextTickRemainTime; BST_UINT32 ulBlockInfo; BST_CORE_PTASK_NODE_STRU *pstPtaskNode; BST_CORE_PTASK_NODE_STRU *pstPtaskNodeNext; BST_BOOL bTimerStop; if( BST_NULL_PTR == pulBlockInfo) { return; } ulBlockInfo = (BST_UINT32 )*pulBlockInfo; BST_DBG_LOG2( "BST_CTaskSchdler::UtranBlockInfoChgProc blockold=u%, blockNew=u%", m_ulBlockInfo,ulBlockInfo); if ( m_ulBlockInfo == ulBlockInfo ) { return; } m_ulBlockInfo = ulBlockInfo; if ( BST_AS_UNBLOCKED == m_ulBlockInfo ) { BST_DBG_LOG1( "BST_CTaskSchdler::UtranBlockInfoChgProc :%d", m_bTaskMissExec ); if(BST_FALSE == m_bTaskMissExec) { return; } lTaskCnt = lstCount( &g_stPTaskList ); BST_DBG_LOG1( "BST_CTaskSchdler::UtranBlockInfoChgProc TaskNum=u%", lTaskCnt ); if ( 0 == lTaskCnt ) { return; } ulNextTickRemainTime = 0; bTimerStop = BST_OS_TimerIsStop( m_ulTimerId ); if ( BST_FALSE == bTimerStop ) { ulNextTickRemainTime = BST_OS_TimeGetRemain( m_ulTimerId ); BST_OS_TimerStop ( m_ulTimerId ); } BST_DBG_LOG2( "BST_CTaskSchdler::UtranBlockInfoChgProc stop:%d,timerremain=u%", bTimerStop,ulNextTickRemainTime ); /* * 遍历任务列表,获取任务并进行相应调度 */ for ( pstPtaskNode = ( BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = pstPtaskNodeNext ) { pstPtaskNodeNext = ( BST_CORE_PTASK_NODE_STRU *) lstNext((NODE *)pstPtaskNode); if ( BST_NULL_PTR == pstPtaskNode->pcTask ) { continue; } /* * 如果任务不为空,则根据状态进行调度 */ TrigScheduleTask ( pstPtaskNode->pcTask); } if((0 == ulNextTickRemainTime) || (ulNextTickRemainTime > BST_TASK_SYS_BASE_TIMELEN)) { ulNextTickRemainTime = BST_TASK_SYS_BASE_TIMELEN; } BST_OS_TimerStart ( m_ulTimerId, ulNextTickRemainTime ); } }