Commit aa17b1ac authored by berge's avatar berge
Browse files

Added additional check to avoid erroneous double synchronisation from same component

parent 2031aaaa
Loading
Loading
Loading
Loading
+41 −10
Original line number Original line Diff line number Diff line
@@ -728,29 +728,39 @@ module LibCommon_Sync {
        tc_sync.start(p_execTimeLimit) ;
        tc_sync.start(p_execTimeLimit) ;
        alt{
        alt{
          [v_noOfRecvdSyncMsgsIntermediate != p_NoOfClientIntermediate]  syncPort.receive(m_syncClientReady(p_syncIdIntermediate)) -> sender v_clientRef {
          [v_noOfRecvdSyncMsgsIntermediate != p_NoOfClientIntermediate]  syncPort.receive(m_syncClientReady(p_syncIdIntermediate)) -> sender v_clientRef {
              if(not f_isPresentInArray(v_clientRef, v_clientRefsIntermediate)) {
                  v_clientRefsIntermediate[v_noOfRecvdSyncMsgsIntermediate] := v_clientRef;
                  v_clientRefsIntermediate[v_noOfRecvdSyncMsgsIntermediate] := v_clientRef;
                  v_noOfRecvdSyncMsgsIntermediate := v_noOfRecvdSyncMsgsIntermediate + 1;
                  v_noOfRecvdSyncMsgsIntermediate := v_noOfRecvdSyncMsgsIntermediate + 1;
                  if (v_noOfRecvdSyncMsgsIntermediate == p_NoOfClientIntermediate) {
                  if (v_noOfRecvdSyncMsgsIntermediate == p_NoOfClientIntermediate) {
                      f_serverSendToAllClients(v_clientRefsIntermediate, m_syncServerReady(p_syncIdIntermediate));
                      f_serverSendToAllClients(v_clientRefsIntermediate, m_syncServerReady(p_syncIdIntermediate));
                  }
                  }
              }
              repeat;
              repeat;
            }
            }
          []  syncPort.receive(m_syncClientReady(p_syncId)) -> sender v_clientRef {
          []  syncPort.receive(m_syncClientReady(p_syncId)) -> sender v_clientRef {
              if(not f_isPresentInArray(v_clientRef, v_clientRefs)) {
                  v_clientRefs[v_noOfRecvdSyncMsgs] := v_clientRef;
                  v_clientRefs[v_noOfRecvdSyncMsgs] := v_clientRef;
                  v_noOfRecvdSyncMsgs := v_noOfRecvdSyncMsgs + 1;
                  v_noOfRecvdSyncMsgs := v_noOfRecvdSyncMsgs + 1;
              }
              if ( v_noOfRecvdSyncMsgs != p_NoOfClients ) { repeat; }
              if ( v_noOfRecvdSyncMsgs != p_NoOfClients ) { repeat; }
            }
            }
          []  syncPort.receive(m_syncClientStop) -> sender v_clientRef {
          []  syncPort.receive(m_syncClientStop) -> sender v_clientRef {
              log("**** f_serverSyncClientsTimed: Sync server received STOP signal from a client - server will wait for all clients to reach their next synchronization point and then stop them! ****") ;
              log("**** f_serverSyncClientsTimed: Sync server received STOP signal from a client - server will wait for all clients to reach their next synchronization point and then stop them! ****") ;
              v_stopClients := true;
              v_stopClients := true;
              if(not f_isPresentInArray(v_clientRef, v_clientRefs)) {
                  v_clientRefs[v_noOfRecvdSyncMsgs] := v_clientRef;
                  v_clientRefs[v_noOfRecvdSyncMsgs] := v_clientRef;
                  v_noOfRecvdSyncMsgs := v_noOfRecvdSyncMsgs + 1;
                  v_noOfRecvdSyncMsgs := v_noOfRecvdSyncMsgs + 1;
              }
              if ( v_noOfRecvdSyncMsgs != p_NoOfClients ) { repeat; }
              if ( v_noOfRecvdSyncMsgs != p_NoOfClients ) { repeat; }

            }
            }
          []  syncPort.receive(m_syncClientReady(?)) -> sender v_clientRef {
          []  syncPort.receive(m_syncClientReady(?)) -> sender v_clientRef {
              log("**** f_serverSyncClientsTimed: Sync server received client sync message with incorrect synchronization point id which is currently not handled - server will stop all clients! ****") ;
              log("**** f_serverSyncClientsTimed: Sync server received client sync message with incorrect synchronization point id which is currently not handled - server will stop all clients! ****") ;
              v_stopClients := true;
              v_stopClients := true;
                v_clientRefs[v_noOfRecvdSyncMsgs] := v_clientRef; }
              if(not f_isPresentInArray(v_clientRef, v_clientRefs)) {
                  v_clientRefs[v_noOfRecvdSyncMsgs] := v_clientRef; 
              }
          }
          []  syncPort.receive(SyncCmd :? ) {
          []  syncPort.receive(SyncCmd :? ) {
              log("**** f_serverSyncClientsTimed: Sync server received (invalid) sync message from other sync server - server will stop all clients! ****") ;
              log("**** f_serverSyncClientsTimed: Sync server received (invalid) sync message from other sync server - server will stop all clients! ****") ;
              v_stopClients := true; }
              v_stopClients := true; }
@@ -1305,9 +1315,30 @@ module LibCommon_Sync {
        } // end alt
        } // end alt
        // cover case that shut down default is NOT activated
        // cover case that shut down default is NOT activated
        setverdict(inconc);
        setverdict(inconc);
          mtc.stop;
          //mtc.stop;
		syncPort.send(m_syncServerStop) to self; // this MUST be _server_ for the default to catch!
		tc_sync.start(PX_TSYNC_TIME_LIMIT);
		alt{
		  [] tc_sync.timeout{
			  log("**** f_selfSyncStop: Stopping MTC without shutdown - either no shutdown default active or missing syncPort connection ****") ;
			  setverdict(inconc);
			  stop ;
			 }
		}//end alt
		tc_sync.stop;
		stop; // if shutdown default is not activated or if it does not stop
      } // end function f_serverWaitForAllClientsToShutDown
      } // end function f_serverWaitForAllClientsToShutDown


		function f_isPresentInArray(in ClientSyncComp p_clientRef, in ClientSyncCompList p_clientRefs)
		return boolean {
			var integer i;
			for(i:=0; i < sizeof(p_clientRefs); i:=i+1) {
				if(p_clientRefs[i] == p_clientRef) {
					return true;
				}
			}
			return false;
		}
    } // end group otherSyncFunctions
    } // end group otherSyncFunctions


  } // end group otherSyncDefinitions
  } // end group otherSyncDefinitions