📄 rticore.c
字号:
fflush(cd); } } if (CRTI.debug > 1) { fprintf(cd,"core_FlushQueueRequestDelivery: "); fprintf(cd,"PendingTime is %16.10f ",CRTI.PendingTime); fprintf(cd,"MinDelivered is %16.10f\n",CRTI.MinDelivered); fprintf(cd,"LBTS is %16.10f\n",CRTI.LBTS); fprintf(cd,"LBTSQual is %d\n",CRTI.LBTSQual); fflush(cd); } return (status);}/*----------------------------------------------------------------------------*//* * core_TryToRelease() * * This function is only used by NER and NERA. it will release messages * that are safe, and less than the pending time. it returns the number * of released messages, and their (common) timestamp. Release qual is necessary * to indicate that their may or may not be more messages. * * ReleaseTime and ReleaseQual are not changed if no messages were deliverable * */int core_TryToRelease(TM_Time *ReleaseTime, TM_TimeQual *ReleaseQual){ TM_Time minTS; char *Data; long MsgSize, MsgType; int Deliveries = 0; if (!((CRTI.PendingRequest != NER) || (CRTI.PendingRequest != NERA))) { if (1 ||CRTI.debug > 0) { fprintf(cd,"core_TryToRelease: Error! NER or NERA Not Pending.\n"); fflush(cd); } exit(1); } /* * find min time stamp of any message in queue (and hold on to it) */ minTS = RTI_TSOMin(); if (CRTI.debug > 1) { fprintf(cd,"core_TryToRelease: \n"); fprintf(cd,"PendingTime is %16.10f \n",CRTI.PendingTime); fprintf(cd,"TSO Min Time is %16.10f\n",minTS); fprintf(cd,"LBTS is %16.10f\n",CRTI.LBTS); fprintf(cd,"LBTSQual is %d\n",CRTI.LBTSQual); fflush(cd); } /* * if there are deliverable messages */ if ( TM_LE(minTS, CRTI.PendingTime) ) { if (TM_GT(CRTI.LBTS, minTS) ) { *ReleaseTime = minTS; *ReleaseQual = TM_TIME_QUAL_EXCL; /* * deliver messages */ while ( TM_EQ(RTI_TSOMin(),minTS) && ( (Data = RTI_TSOPop(&minTS,&MsgSize, &MsgType)) != NULL) ) { RTI_DeliverOneMessage(minTS,Data,MsgSize,MsgType); Deliveries++; } } else if (TM_EQ(CRTI.LBTS, minTS)) { if ((CRTI.PendingRequest == NERA) || (CRTI.LBTSQual == TM_TIME_QUAL_EXCL ) ) { *ReleaseTime = minTS; *ReleaseQual = CRTI.LBTSQual; /* * deliver messages */ while ( TM_EQ(RTI_TSOMin(),minTS) && ( (Data = RTI_TSOPop(&minTS,&MsgSize, &MsgType)) != NULL) ) { RTI_DeliverOneMessage(minTS,Data,MsgSize,MsgType); Deliveries++; } } } } return (Deliveries);}/*----------------------------------------------------------------------------*/static fdkErrorCode core_StartLBTS(){ fdkErrorCode status = fdkSUCCEEDED; /* Additions by TM to simplify in the aftermath of Kalyans TM changes */ /* This is the one and only place to start an LBTS locally */ if (CRTI.PendingRequest == NO_REQ) { if (1 || CRTI.debug > 0) { fprintf(cd,"core_StartLBTS: Error! No request pending "); fflush(cd); } exit(1); } /* Make sure there no pending LBTS computations, before we start one */ if (CRTI.debug > 1) { fprintf(cd,"core_StartLBTS: Starting Local LBTS computation "); fflush(cd); } if (CRTI.NPendingLBTS > 0) { if (CRTI.debug > 1) { fprintf(cd," -- Ignoring StartLBTS since a computation is already in progress\n"); fflush(cd); } } else { /* * should we actually be keeping track of the current transaction? * or is just the most recently completed one ok? -TM */ long Transaction; if ( (status = core_Compute_Local_Min()) != fdkSUCCEEDED) return(status); if (TM_StartLBTS(CRTI.LocalMin, CRTI.LocalMinQual, core_MyLBTSDone, &Transaction) != TM_SUCCESS) { if (1 || CRTI.debug > 0) { fprintf(cd,"core_StartLBTS: LBTS computation failed to start\n"); fflush(cd); } return(fdkCNSLBTS); } CRTI.NPendingLBTS++; if (CRTI.debug > 1) { fprintf (cd,"core_StartLBTS: started trans=%ld,reported = %16.10f\n", Transaction,CRTI.LocalMin); fflush(cd); } } return(status);}/*----------------------------------------------------------------------------*//* * core_Compute_Local_Min() * * This function computes the localMin value to be reported under various * conditions * * notes: * TM - this has been looked at pretty well know. * */static fdkErrorCode core_Compute_Local_Min(){ TM_Time Candidate_Time, Candidate_LA; /* * Additions by TM to simplify in the aftermath of Kalyans TM changes * This procedure is the one and only place we compute local value for LBTS */ switch (CRTI.PendingRequest) { case NER: { /* * There is nothing special about lower bound from NER. * * The new min is the Candidate. * If ZLA, the time qual must be EXCL, else, INCL * */ Candidate_Time = TM_Min(CRTI.PendingTime, RTI_TSOMin()); Candidate_LA = TM_Max(CRTI.TargetLA, TM_Sub(CRTI.LookAhead, TM_Sub(Candidate_Time, CRTI.CurrentTime))); CRTI.LocalMin = TM_Add(Candidate_Time, Candidate_LA); if (TM_isZero(Candidate_LA)) CRTI.LocalMinQual = TM_TIME_QUAL_EXCL; else CRTI.LocalMinQual = TM_TIME_QUAL_INCL; } break; case NERA: { /* * For NERA, we have the additional restriction of not going backwards * when ZLA, so we must inherit the current QUAL if the Candidate is * the same as the Current time. * */ Candidate_Time = TM_Min(CRTI.PendingTime, RTI_TSOMin()); Candidate_LA = TM_Max(CRTI.TargetLA, TM_Sub(CRTI.LookAhead, TM_Sub(Candidate_Time, CRTI.CurrentTime))); CRTI.LocalMin = TM_Add(Candidate_Time, Candidate_LA); if ( TM_isZero(Candidate_LA) && TM_EQ( Candidate_Time,CRTI.CurrentTime)) CRTI.LocalMinQual = CRTI.CurrentQual; else CRTI.LocalMinQual = TM_TIME_QUAL_INCL; } break; case TAR: { /* * There is nothing special about lower bound from TAR. * * The new min is based on the pending time, since we will not * grant until we can grant to pending time. * If ZLA, the time qual must be EXCL, else, INCL * */ Candidate_Time = CRTI.PendingTime; Candidate_LA = TM_Max(CRTI.TargetLA, TM_Sub(CRTI.LookAhead, TM_Sub(Candidate_Time, CRTI.CurrentTime))); CRTI.LocalMin = TM_Add(Candidate_Time, Candidate_LA); if (TM_isZero(Candidate_LA)) CRTI.LocalMinQual = TM_TIME_QUAL_EXCL; else CRTI.LocalMinQual = TM_TIME_QUAL_INCL; } break; case TARA: { /* * For TERA, we have the additional restriction of not going backwards * when ZLA, so we must inherit the current QUAL if the Candidate is * the same as the Current time. * */ Candidate_Time = CRTI.PendingTime; Candidate_LA = TM_Max(CRTI.TargetLA, TM_Sub(CRTI.LookAhead, TM_Sub(Candidate_Time, CRTI.CurrentTime))); CRTI.LocalMin = TM_Add(Candidate_Time, Candidate_LA); if ( TM_isZero(Candidate_LA) && TM_EQ( Candidate_Time,CRTI.CurrentTime)) CRTI.LocalMinQual = CRTI.CurrentQual; else CRTI.LocalMinQual = TM_TIME_QUAL_INCL; } break; case FQR: { /* * There seems to be some confusion about how an FQR is supposed to work * according to the HLA I/F spec (1.3), time should be advanced as far as possible, up * to the request time. no mention of the TSOmin is made. This is a better * implementation, as specified in the 1516. * * FQR is patterned after NER, except that we will not report greater than a * pending retraction (to allow the federate to retract subsequent messages.) * * we also keep track of the mininum time that has been delivered, so we don't have * to wait for LBTS to flush the messages. We know we wont grant past MinDelivered, * so we always use that instead of PendingTime (MinDelivered is initialized to * PendingTime) */ Candidate_Time = TM_Min(CRTI.MinDelivered, RTI_TSOMin()); Candidate_LA = TM_Max(CRTI.TargetLA, TM_Sub(CRTI.LookAhead, TM_Sub(Candidate_Time, CRTI.CurrentTime))); CRTI.LocalMin = TM_Add(Candidate_Time, Candidate_LA); /* * This is a bit confusing. If the LocalMin is the same as core_MinRetract, * Then we have to report INCL, since additional retracts could be sent with * the same timestamp. * else, we report like an NER */ if (TM_LT(core_MinRetract(), CRTI.LocalMin )) { CRTI.LocalMin = core_MinRetract(); CRTI.LocalMinQual = TM_TIME_QUAL_INCL; } else if ( TM_isZero(Candidate_LA) ) CRTI.LocalMinQual = TM_TIME_QUAL_EXCL; else CRTI.LocalMinQual = TM_TIME_QUAL_INCL; } break; default: { /* No Pending TM requests * * our current lower bound, if nothing is pending, is simply * the least timestamp that the federate is allowed to send. */ CRTI.LocalMin = TM_Add(CRTI.CurrentTime, CRTI.LookAhead); if (TM_isZero(CRTI.LookAhead)) CRTI.LocalMinQual = CRTI.CurrentQual; else CRTI.LocalMinQual = TM_TIME_QUAL_INCL; } break; } /* Do some consistency checking */ /*XXX KALYAN Added LookAhead to LocalMin in the predicates*/ if ( TM_LT(TM_Add(CRTI.LocalMin,CRTI.LookAhead),CRTI.LBTS) || ( TM_EQ(TM_Add(CRTI.LocalMin,CRTI.LookAhead),CRTI.LBTS) && (CRTI.LocalMinQual < CRTI.LBTSQual) ) ) { if (1 || CRTI.debug > 0) { Core_PrintRTIState(CRTI.dout); TM_PrintState(); fprintf(cd, "core_Compute_Local_Min: ERROR! LocalMin of %308.300f Decreasing from", CRTI.LocalMin); fprintf(cd,"previous LBTS of %308.300f\n",CRTI.LBTS); fprintf(cd,"LookAhead %308.300lf\n",CRTI.LookAhead); fprintf(cd,"Difference of %308.300lf\n",TM_Sub(CRTI.LBTS,CRTI.LocalMin)); fprintf(cd,"Diff is %308.300lf %sve", TM_Sub(TM_Add(CRTI.LocalMin,CRTI.LookAhead),CRTI.LBTS),TM_GT(TM_ZERO,TM_Sub(TM_Add(CRTI.LocalMin,CRTI.LookAhead),CRTI.LBTS))?"-":"+"); fflush(cd); }if(0)/*XXX KALYAN*/ exit(1); return (fdkFAILED); } return (fdkSUCCEEDED);}/*----------------------------------------------------------------------------*/static long core_MyLBTSStarted(long Trans, TM_Time *MyTime, TM_TimeQual *MyTimeQual, TM_LBTSDoneProc *MyProc){ long retval = TM_ACCEPT; if (CRTI.debug > 1) { fprintf(cd,"\nMyLBTSStarted:..Trans=%ld",Trans); fflush(cd); } /* if disabled, defer start */ if( ! CRTI.LBTSEnabled ) { CRTI.NLBTSDeferred++; /*This should never be called when NLBTSDeferred != 0*/ retval = TM_DEFER; } else { /* accept computation, report local minimum */ core_Compute_Local_Min(); *MyTime = CRTI.LocalMin; *MyTimeQual = CRTI.LocalMinQual; *MyProc = core_MyLBTSDone; CRTI.NPendingLBTS++; /*XXX KALYAN Added LookAhead to MyTime in the predicates*/ if( TM_LT(TM_Add(*MyTime,CRTI.LookAhead),CRTI.LBTS) ) { if (1 || CRTI.debug > 0) { TM_PrintState(); fprintf(cd,"\nMyLBTSStarted: MyTime+LA = %16.10f \n", *MyTime);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -