private void PackageStatusInfo() { LocalEventQueue <SequenceStatusInfo> statusQueue = _context.StatusQueue; while (!_cancellation.IsCancellationRequested) { // 标记事件处理flag为阻塞中 Thread.MemoryBarrier(); Thread.VolatileWrite(ref _eventProcessFlag, 0); SequenceStatusInfo statusInfo = statusQueue.WaitUntilMessageCome(); // 如果为null,StatusQueue已经停止接收,直接跳出 if (null == statusInfo) { return; } // 标记事件处理flag为处理中 Thread.MemoryBarrier(); Thread.VolatileWrite(ref _eventProcessFlag, 1); SendSequenceStatusMessage(statusInfo); // 标记事件处理flag为处理结束 Thread.MemoryBarrier(); Thread.VolatileWrite(ref _eventProcessFlag, 2); } // 标记事件处理flag为结束状态 Thread.MemoryBarrier(); Thread.VolatileWrite(ref _eventProcessFlag, 3); }
private void ProcessInternalMessage(object state) { LocalEventQueue <EventInfoBase> internalEventQueue = _globalInfo.EventQueue; try { while (!_cancellation.IsCancellationRequested) { EventInfoBase eventInfo = internalEventQueue.WaitUntilMessageCome(); if (null == eventInfo) { return; } _eventProcessActions[eventInfo.GetType().Name].Invoke(eventInfo); } // 处理完堆积的内部消息,然后停止 while (internalEventQueue.Count > 0) { EventInfoBase eventInfo = internalEventQueue.Dequeue(); _eventProcessActions[eventInfo.GetType().Name].Invoke(eventInfo); } } catch (TestflowException ex) { _globalInfo.LogService.Print(LogLevel.Fatal, CommonConst.PlatformLogSession, ex); _globalInfo.StateMachine.State = RuntimeState.Error; throw; } catch (ThreadAbortException) { _globalInfo.LogService.Print(LogLevel.Warn, CommonConst.PlatformLogSession, $"thread {Thread.CurrentThread.Name} is stopped abnormally"); } catch (Exception ex) { _globalInfo.EventQueue.Enqueue(new ExceptionEventInfo(ex)); _globalInfo.LogService.Print(LogLevel.Fatal, CommonConst.PlatformLogSession, ex, "Engine collapsed by fatal error."); _globalInfo.StateMachine.State = RuntimeState.Collapsed; } }