⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rticore.c

📁 基于linux环境的ns2多机并行仿真补丁
💻 C
📖 第 1 页 / 共 5 页
字号:
  if (p == NULL)    return(fdkFAILED);  else    return(fdkSUCCEEDED); }/*----------------------------------------------------------------------------*/fdkErrorCode Core_RegisterDeliverROEvents(DeliverROEventsProc p){  RTI_DeliverROEvents = p;  if (p == NULL)    return(fdkFAILED);  else    return(fdkSUCCEEDED);}/*----------------------------------------------------------------------------*/fdkErrorCode Core_RegisterDeliverTSOEvents(DeliverTSOEventsProc p){  RTI_DeliverTSOEvents = p;  if (p == NULL)    return(fdkFAILED);  else    return(fdkSUCCEEDED);}/*----------------------------------------------------------------------------*/fdkErrorCode Core_RegisterTimeAdvanceGrant(TimeAdvanceGrantProc p){  RTI_TimeAdvanceGrant = p;  if (p == NULL)    return(fdkFAILED);  else     return(fdkSUCCEEDED);}/*----------------------------------------------------------------------------*/fdkErrorCode Core_RegisterTSOMin(TSOMinProc p){  RTI_TSOMin = p;  if (p == NULL)    return(fdkFAILED);  else    return(fdkSUCCEEDED);}/*----------------------------------------------------------------------------*/fdkErrorCode Core_RegisterTSOPop(TSOPopProc p){  RTI_TSOPop = p;  if (p == NULL)    return(fdkFAILED);  else    return(fdkSUCCEEDED);}/*----------------------------------------------------------------------------*//*           CurrentTime, CurrentQual, LookAhead, ValidateTimestamp           *//*----------------------------------------------------------------------------*/TM_Time Core_GetCurrentTime(void){  return(CRTI.CurrentTime);}/*----------------------------------------------------------------------------*/TM_TimeQual Core_GetCurrentQual(void){  return(CRTI.CurrentQual);}/*----------------------------------------------------------------------------*/TM_Time Core_GetLookAhead(void){   return(CRTI.LookAhead);}/*----------------------------------------------------------------------------*/TM_Time Core_GetLBTS(void){   return(CRTI.LBTS);}/*----------------------------------------------------------------------------*/TM_Time Core_GetPendingTime(void){  return(CRTI.CurrentTime);}/*----------------------------------------------------------------------------*/TM_TimeQual Core_GetPendingQual(void){  return(CRTI.CurrentQual);}/*----------------------------------------------------------------------------*/TM_Time Core_GetPendingLookAhead(void){   return(CRTI.LookAhead);}/*----------------------------------------------------------------------------*//* KALYAN Topology extensions begin *//*----------------------------------------------------------------------------*/typedef struct { MCAST_Handle h; TM_Time la; } CoreTSOGroup;typedef struct { int n, mx; CoreTSOGroup *g; } CoreTSOGroupList;static CoreTSOGroupList tsog;/*----------------------------------------------------------------------------*/int Core_FindTSOGroup(MCAST_Handle h){    int i=0;    for(i=0;i<tsog.n;i++) if(MCAST_SameGroups(tsog.g[i].h,h)) return i;    return -1;}/*----------------------------------------------------------------------------*/fdkErrorCode Core_TSOifyGroup(MCAST_Handle handle){    if( Core_FindTSOGroup(handle) >= 0 ) return fdkSUCCEEDED;    if( tsog.n >= tsog.mx )    {	void *p = tsog.g;	int n = (tsog.mx += 1000)*sizeof(CoreTSOGroup);        tsog.g = (CoreTSOGroup*) (p ?  realloc(p,n) : malloc(n));    }    assert( tsog.g && tsog.n < tsog.mx );    tsog.g[tsog.n].h = handle;    tsog.g[tsog.n].la = TM_NEG1;    tsog.n++;if(1){printf("Core_TSOifyGroup(\"%s\")\n",MCAST_GetName(handle));fflush(stdout);}    return fdkSUCCEEDED;}/*----------------------------------------------------------------------------*/fdkErrorCode Core_SetGroupLAByHandle(MCAST_Handle handle, TM_Time newLA){    TM_Time *pla = 0;    int i = Core_FindTSOGroup(handle);    assert( i >= 0 );    pla = &tsog.g[i].la;    if(TM_LT(*pla, TM_ZERO)) *pla = newLA;    else *pla = TM_Min(*pla, newLA);    return fdkSUCCEEDED;}/*----------------------------------------------------------------------------*/fdkErrorCode Core_SetGroupLAByName(char *group_name, TM_Time newLA){    MCAST_Handle handle = 0;    MCAST_GetHandle( group_name, &handle );    assert( handle );    return Core_SetGroupLAByHandle( handle, newLA );}/*----------------------------------------------------------------------------*/fdkErrorCode Core_FinalizeTopology(void){    int i=0, pe=0, nmemb=0, mems[MAX_PE];if(1){printf("Core_FinalizeTopology(): ng=%d\n",tsog.n);fflush(stdout);}    for( i = 0; i < tsog.n; i++ )    {	TM_Time *pla = &tsog.g[i].la;	if( TM_LT(*pla, TM_ZERO) ) *pla = CRTI.LookAhead;	MCAST_GetMembers(tsog.g[i].h, &nmemb, mems, MAX_PE);	assert(nmemb < MAX_PE);if(1){printf("\tGroup %d (\"%s\") #members=%d\n",i,MCAST_GetName(tsog.g[i].h),nmemb);fflush(stdout);}	for( pe = 0; pe < nmemb; pe++ )	{	    /*Assume duplex memberships, i.e.,*/	    /*every member is a publisher AND subscriber*/	    TM_TopoAddSender( mems[pe] );	    TM_TopoAddReceiver( mems[pe], *pla );	}    }if(CRTI.debug>=0){TM_TopoPrint();fflush(stdout);}    return fdkSUCCEEDED;}/*----------------------------------------------------------------------------*//* KALYAN Topology extensions end *//*----------------------------------------------------------------------------*//*----------------------------------------------------------------------------*/fdkErrorCode Core_SetLookAhead(TM_Time newLA){if(CRTI.debug>=0){printf("Core_SetLookAhead(%lf)\n",newLA);fflush(stdout);}  if (Core_EnsureRequestNotPending() == fdkTMPENDING)    return (fdkTMPENDING);  TM_TopoSetMinExternalLA(newLA); /*KALYAN*/  if (TM_GT(newLA,CRTI.LookAhead))   {     CRTI.LookAhead = newLA;     CRTI.TargetLA = newLA;     return(fdkSUCCEEDED);   }   else   {     CRTI.TargetLA = newLA;     return(fdkSUCCEEDED);   }}/*----------------------------------------------------------------------------*/int     Core_ValidateTimestamp(TM_Time timestamp){     TM_Time LowerBound;   TM_TimeQual Qual;   if (CRTI.PendingRequest == NO_REQ )    {       LowerBound = TM_Add(CRTI.CurrentTime, CRTI.LookAhead);       if (TM_isZero(CRTI.LookAhead))           Qual = CRTI.CurrentQual;       else           Qual = TM_TIME_QUAL_INCL;          }   else    {/*       LowerBound = TM_Add(CRTI.PendingTime, CRTI.LookAhead);       if (TM_isZero(CRTI.LookAhead))           Qual = CRTI.PendingQual;       else           Qual = TM_TIME_QUAL_INCL;*//* * This should work during a time advancing state, when  *  localMin may be <= pending time.  */       LowerBound = CRTI.LocalMin;        Qual = CRTI.LocalMinQual;   }   if (TM_GT(timestamp, LowerBound)) return (TRUE);   if (TM_LT(timestamp, LowerBound)) return (FALSE);   if (Qual == TM_TIME_QUAL_EXCL) return (FALSE);   return (TRUE);}/*----------------------------------------------------------------------------*/void Core_ConsiderIncomingTSOMsg(TM_Time msg_ts, TM_TagType tm_tag)   /*KALYAN*/{    TM_In(TM_Add(msg_ts, CRTI.LookAhead), tm_tag);}/*----------------------------------------------------------------------------*/void Core_ConsiderOutgoingTSOMsg(TM_Time msg_ts, int count)           /*KALYAN*/{    TM_Out(msg_ts, count);}/*----------------------------------------------------------------------------*//*                         Core_DisableLBTS, Core_EnableLBTS                  *//*----------------------------------------------------------------------------*/fdkErrorCode Core_DisableLBTS (void){  CRTI.LBTSEnabled = FALSE;  return(fdkSUCCEEDED); }/*----------------------------------------------------------------------------*/fdkErrorCode Core_EnableLBTS (void){  /*  Enable externally initiated LBTS computations   *  This procedure, and the one above are only useful if an LBTS can    *  be remotely started while the while outside of RTICore_Tick()   *  (i.e. a multi threaded interface implementation)   *  The purpose is to temporarily suspend, then re-   *  initiate any deferred LBTS computations   *  for right now, it is disabled. -TM (03/29/01)   *     */        /*   start up any deferred computations */  if(0) {  long trans;  if (CRTI.NLBTSDeferred>0)  {    if (CRTI.NLBTSDeferred != 1)    {      if (CRTI.debug)      {	    fprintf(cd, "At most 1 LBTS should have  been deferred %d\n", 		CRTI.NLBTSDeferred);	    fflush(cd);      }      return(fdkNLBTSERROR);    }    core_Compute_Local_Min();    TM_StartLBTS(CRTI.LocalMin, CRTI.LocalMinQual, core_MyLBTSDone, &trans);  }  CRTI.NLBTSDeferred = 0;}  CRTI.LBTSEnabled = TRUE;  return(fdkSUCCEEDED); }/*----------------------------------------------------------------------------*//*                  Time Requests Functions (NER, TAR, FQR )                  *//*----------------------------------------------------------------------------*/fdkErrorCode Core_EnsureRequestNotPending () {  if (CRTI.PendingRequest != NO_REQ )  {    if (CRTI.debug > 1)    {        fprintf(cd,"RTICore: Request enum %d already pending.\n", CRTI.PendingRequest); 	    fflush(cd);    }    return(fdkTMPENDING);  }  return(fdkSUCCEEDED);   }/*----------------------------------------------------------------------------*/fdkErrorCode Core_EnsureRequestTimeNotPast (TM_Time RequestTime) {  if( TM_GT(CRTI.CurrentTime, RequestTime) )  {    if (CRTI.debug > 1)    {       fprintf(cd,"RTICore: Request time already passed.\n");       fflush(cd);    }    return(fdkTIMEPASSED);  }  return(fdkSUCCEEDED); }/*----------------------------------------------------------------------------*/fdkErrorCode Core_SetPendingQual () {    fdkErrorCode status = fdkSUCCEEDED;    if ( CRTI.PendingRequest == NO_REQ )    {        if (1 || CRTI.debug > 0)        {            fprintf(cd,"Core_SetPendingQual: ERROR! No Request pending.\n"); 	        fflush(cd);        }        status = fdkFAILED;        return (status);    }      /*  if I am requesting the current time, I inherit the current Qual  */    if ( TM_EQ(CRTI.PendingTime,CRTI.CurrentTime) )        CRTI.PendingQual = CRTI.CurrentQual;    else         CRTI.PendingQual = TM_TIME_QUAL_INCL;            /*  For TAR and NER only, if I am asking for Zero LA, and can get there */    /*   by the request then I must bump the pending qual up to EXCL        */        if (( CRTI.PendingRequest == NER) || ( CRTI.PendingRequest == TAR))    {        /* TargetLA is always <= LookAhead so this also checks LookAhead  */        if (TM_isZero(CRTI.TargetLA) )        {            /* if I get to ZLA by Pending Time, then I have to be EXCL*/            if (TM_GE(CRTI.PendingTime, TM_Add(CRTI.CurrentTime, CRTI.LookAhead)))                CRTI.PendingQual = TM_TIME_QUAL_EXCL;        }    }    return(status);}/*----------------------------------------------------------------------------*//* * Note from Thom.  This is a candidate for a generic time advance request * the intent is to  generalize .  not functional yet. *//*----------------------------------------------------------------------------*/fdkErrorCode Core_Request (CoreRequest RequestType, TM_Time RequestTime){  fdkErrorCode status = fdkSUCCEEDED;  int needToStartLBTS = 0;  if (CRTI.debug > 1)  {     fprintf(cd,"Core_Request: AdvanceTime = %12.6f\n", RequestTime);     fflush(cd);  }    /* error if request is already pending */  status = Core_EnsureRequestNotPending();  if ( status != fdkSUCCEEDED) return (status);  /* error if time has already passed*/  status = Core_EnsureRequestTimeNotPast(RequestTime);  if( status != fdkSUCCEEDED ) return (status);     CRTI.PendingRequest = RequestType;    CRTI.PendingTime = RequestTime;      status = Core_SetPendingQual();  if (status != fdkSUCCEEDED )  {    if (CRTI.debug > 0)    {        fprintf(cd,"RTICore: NER Failed to Set the PendingQual\n");        fflush(cd);    }    return (status);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -