/// <see cref="ITimeSource.UnblockHandle"/>
        public bool UnblockHandle(TimeHandle handle)
        {
            handle.Trace("About to unblock this handle");

            if (isPaused)
            {
                this.Trace("Time source is paused - returning false");
                return(false);
            }

            bool result;

            using (sync.HighPriority)
            {
                DebugHelper.Assert(handles.All.Contains(handle), "Unblocking a handle that is not registered");

                sync.WaitWhile(() => recentlyUnblockedSlaves.Contains(handle), "Wait until the previous unblocking status is read");

                handle.Trace($"Unblocking status: {(!isStarted ? "aborting" : "unblocking")}");
                result = isStarted;

                if (isStarted)
                {
                    recentlyUnblockedSlaves.Add(handle);
                    this.Trace($"UnblockHandle: Number of unblocked slaves set to: {recentlyUnblockedSlaves.Count}");
                    blockingEvent.Set();
                }
            }

            return(result);
        }
Пример #2
0
 /// <summary>
 /// Disposes this instance.
 /// </summary>
 public override void Dispose()
 {
     this.Trace("Disposing...");
     base.Dispose();
     base.Stop();
     lock (locker)
     {
         TimeHandle?.Dispose();
     }
     StopDispatcher();
     this.Trace("Disposed");
 }
Пример #3
0
        /// <see cref="ITimeSource.RegisterSink">
        public void RegisterSink(ITimeSink sink)
        {
            using (sync.HighPriority)
            {
                var handle = new TimeHandle(this, sink)
                {
                    SourceSideActive = isStarted
                };
                StopRequested += handle.RequestPause;
                handles.Add(handle);
#if DEBUG
                this.Trace($"Registering sink ({(sink as IIdentifiable)?.GetDescription()}) in source ({this.GetDescription()}) via handle ({handle.GetDescription()})");
#endif
                // assigning TimeHandle to a sink must be done when everything is configured, otherwise a race condition might happen (dispatcher starts its execution when time source and handle are not yet ready)
                sink.TimeHandle = handle;
            }
        }
        /// <see cref="ITimeSource.ReportTimeProgress">
        public void ReportTimeProgress(TimeHandle h, TimeInterval diff)
        {
            if (diff.Ticks == 0)
            {
                return;
            }

            var currentCommonElapsedTime = handles.CommonElapsedTime;

            if (currentCommonElapsedTime > previousElapsedVirtualTime)
            {
                var timeDiff = currentCommonElapsedTime - previousElapsedVirtualTime;
                this.Trace($"Reporting time passed: {timeDiff}");
                TimePassed?.Invoke(timeDiff);
                previousElapsedVirtualTime = currentCommonElapsedTime;
            }
        }