예제 #1
0
        private void _ThreadFunc()
        {
            // Thread main loop
            try {
                IOutputDeviceUpdateSignaler signaler = _CreateOutputDeviceUpdateSignaler();

                while (_threadState != ExecutionState.Stopping)
                {
                    Execution.UpdateState();
                    _UpdateOutputDevice();

                    _WaitOnSignal(signaler);
                    _WaitOnPause();
                }

                _threadState = ExecutionState.Stopped;
                _finished.Set();
            } catch (Exception ex) {
                // Do this before calling OnError so that we can be in the stopped state.
                // Otherwise, we'll have a deadlock as the event causes a shutdown which
                // waits for the thread to end.
                _threadState = ExecutionState.Stopped;
                _finished.Set();

                VixenSystem.Logging.Error("Controller " + OutputDevice.Name + " error", ex);
                OnError();
            }
        }
        private IOutputDeviceUpdateSignaler _CreateOutputDeviceUpdateSignaler()
        {
            IOutputDeviceUpdateSignaler signaler = OutputDevice.UpdateSignaler ?? new IntervalUpdateSignaler();

            signaler.OutputDevice = OutputDevice;
            signaler.UpdateSignal = _updateSignalerSync;

            return(signaler);
        }
        private void _WaitOnSignal(IOutputDeviceUpdateSignaler signaler)
        {
            long timeBeforeSignal = _localTime.ElapsedMilliseconds;

            signaler.RaiseSignal();
            //_updateSignalerSync.WaitOne();

            long timeAfterSignal = _localTime.ElapsedMilliseconds;

            _sleepTimeActualValue.Set(timeAfterSignal - timeBeforeSignal);
        }
예제 #4
0
        private void _ThreadFunc()
        {
            // Thread main loop
            try {
                IOutputDeviceUpdateSignaler signaler = _CreateOutputDeviceUpdateSignaler();

                while (_threadState != ExecutionState.Stopping)
                {
                    long nowMs = _localTime.ElapsedMilliseconds;
                    long dtMs  = nowMs - _lastMs;
                    _intervalDeltaValue.Set(Math.Abs(OutputDevice.UpdateInterval - dtMs));
                    _lastMs = nowMs;

                    bool allowed = false;
                    Execution.UpdateState(out allowed);
                    long execMs = _localTime.ElapsedMilliseconds - nowMs;

                    _UpdateOutputDevice();

                    if (allowed)
                    {
                        _executionTimeValue.Set(execMs);
                    }

                    // wait for the next go 'round
                    _WaitOnSignal(signaler);
                    _WaitOnPause();
                }

                _threadState = ExecutionState.Stopped;
                _finished.Set();
            }
            catch (Exception ex) {
                // Do this before calling OnError so that we can be in the stopped state.
                // Otherwise, we'll have a deadlock as the event causes a shutdown which
                // waits for the thread to end.
                _threadState = ExecutionState.Stopped;
                _finished.Set();

                Logging.Error(ex, string.Format("Controller {0} error", OutputDevice.Name));
                OnError();
            }
        }
        private void _ThreadFunc()
        {
            // Thread main loop
            try {
                IOutputDeviceUpdateSignaler signaler = _CreateOutputDeviceUpdateSignaler();

                while (_threadState != ExecutionState.Stopping)
                {
                    long nowMs = _localTime.ElapsedMilliseconds;
                    long dtMs  = nowMs - _lastMs;
                    _lastMs = nowMs;

                    bool allowed = false;
                    var  lastTS  = Execution.UpdateState(out allowed);
                    long execMs  = _localTime.ElapsedMilliseconds - nowMs;

                    _UpdateOutputDevice();
                    long outputMs = _localTime.ElapsedMilliseconds - nowMs - execMs;

                    // instrumentation counters...
                    _intervalDeltaValue.Set(Math.Abs(OutputDevice.UpdateInterval - dtMs));
                    if (allowed)
                    {
                        _executionTimeValue.Set(execMs);
                    }
                    _updateTimeValue.Set(outputMs);

                    // log stuff after real work is done...

                    // prep a sample info string for later...
                    string sampinfo = "";
                    long   sampMs   = 0;
                    foreach (var name in lastTS.Keys)
                    {
                        if (!name.Contains("System"))
                        {
                            sampMs    = (long)lastTS[name].TotalMilliseconds;
                            sampinfo += String.Format("{0}:{1} ", name, sampMs);
                        }
                    }

                    // our cycle jitter was captured above
                    bool jitter = false;
                    if (Math.Abs(OutputDevice.UpdateInterval - dtMs) > 20)
                    {
                        jitter = true;
                        Logging.Debug("hwt jitter:  {0}: nowMs:{1}, dtMs:{2}", OutputDevice.Name, nowMs, dtMs);
                    }

                    // only worry about state sample jitter if it is running
                    long dtMs2 = 0;
                    if (sampMs > 0)
                    {
                        dtMs2    = sampMs - _lastMs2;
                        _lastMs2 = sampMs;
                        if (Math.Abs(OutputDevice.UpdateInterval - dtMs2) > 20 && sampMs > 0 && dtMs2 > 0)
                        {
                            jitter = true;
                            Logging.Debug("samp jitter:  {0}: sampMs:{1}, dts:{2}",
                                          OutputDevice.Name, sampMs, dtMs2);
                        }
                    }
                    // summary output for all threads of jitter...
                    // change the false in statuslog to true to get a no-preview output each time through..
                    bool statuslog = false && (sampMs > 0 && dtMs2 > 0 && !OutputDevice.Name.Contains("Preview"));
                    if (jitter || statuslog)
                    {
                        Logging.Debug("{0}: nowMs:{1}, dtMs:{2}, execMs:{3}, outMs:{4}, ts:{5}, dts={6}",
                                      OutputDevice.Name, nowMs, dtMs, execMs, outputMs, sampinfo, dtMs2);
                    }

                    // wait for the next go 'round
                    _WaitOnSignal(signaler);
                    _WaitOnPause();
                }

                _threadState = ExecutionState.Stopped;
                _finished.Set();
            }
            catch (Exception ex) {
                // Do this before calling OnError so that we can be in the stopped state.
                // Otherwise, we'll have a deadlock as the event causes a shutdown which
                // waits for the thread to end.
                _threadState = ExecutionState.Stopped;
                _finished.Set();

                Logging.ErrorException(string.Format("Controller {0} error", OutputDevice.Name), ex);
                OnError();
            }
        }
예제 #6
0
        private void _WaitOnSignal(IOutputDeviceUpdateSignaler signaler)
        {
            long timeBeforeSignal = _localTime.ElapsedMilliseconds;

            signaler.RaiseSignal();
            //_updateSignalerSync.WaitOne();

            long timeAfterSignal = _localTime.ElapsedMilliseconds;
            _sleepTimeActualValue.Set(timeAfterSignal - timeBeforeSignal);
        }