Exemplo n.º 1
0
        public void Run()
        {
            Contract.Requires <InvalidOperationException>(!Ended);
            Contract.Requires <InvalidOperationException>(!double.IsPositiveInfinity(Peek));
            Contract.Ensures(Ended);

            // Real-time management.
            if (RealTime.Enabled)
            {
                // Set the base UNIX time, used to computed the "wall clock" time of timeout events.
                RealTime.SetCurrentUnixTime();
            }

            this.Timeout(double.MaxValue).Callbacks.Add(e => EndSimulation());
            DoSimulate();
        }
Exemplo n.º 2
0
        public void Run(int until)
        {
            Contract.Requires <InvalidOperationException>(!Ended);
            Contract.Requires <InvalidOperationException>(!double.IsPositiveInfinity(Peek));
            Contract.Requires <ArgumentOutOfRangeException>(IsValidDelay(until), ErrorMessages.InvalidDelay);
            Contract.Ensures(Ended);

            // Real-time management.
            if (RealTime.Enabled)
            {
                // Set the base UNIX time, used to computed the "wall clock" time of timeout events.
                RealTime.SetCurrentUnixTime();
            }

            this.Timeout(until).Callbacks.Add(e => EndSimulation());
            DoSimulate();
        }
Exemplo n.º 3
0
        public void Run(SimEvent until)
        {
            Contract.Requires <InvalidOperationException>(!Ended);
            Contract.Requires <InvalidOperationException>(!double.IsPositiveInfinity(Peek));
            Contract.Requires <ArgumentNullException>(until != null, ErrorMessages.NullEvent);
            Contract.Requires <ArgumentException>(ReferenceEquals(this, until.Env), ErrorMessages.DifferentEnvironment);
            Contract.Requires <ArgumentException>(!until.Failed);
            Contract.Ensures(Ended);

            // Real-time management.
            if (RealTime.Enabled)
            {
                // Set the base UNIX time, used to computed the "wall clock" time of timeout events.
                RealTime.SetCurrentUnixTime();
            }

            // TODO Fix this, since when until is triggered UntilProcess is not immediately triggered.
            Process(UntilProcess(until));
            DoSimulate();
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Sets the simulation time.
        /// </summary>
        /// <param name="nextNow">The new simulation time.</param>
        /// <param name="nextWallClock">The new wall clock, used in real-time mode.</param>
        internal void SetNow(double nextNow, double nextWallClock)
        {
            _prevNow = _now;
            _now     = nextNow;

            // Real-time management.
            if (RealTime.Enabled)
            {
                double delay;
                if (nextNow < double.MaxValue && (delay = (nextWallClock - RealTime.WallClock.UnixTime)) > 0.0)
                {
                    // "delay" is measured in seconds, it must be converted into milliseconds.
#if NET40
                    System.Threading.Thread.Sleep((int)(delay * 1000.0));
#else
                    System.Threading.Tasks.Task.Delay((int)(delay * 1000.0)).Wait();
#endif
                }

                // Update the base UNIX time after having waited.
                RealTime.SetCurrentUnixTime();
            }
        }