public async Task ConsumeReadyJob() { var jobPool = new JobPool <T>(); var readyQueue = new ReadyQueue <T>(); while (true) { try { var job = await readyQueue.GetJobFromReadyQueue(typeof(T).Name, 3); if (job == null) { await Task.Delay(500); continue; } await jobPool.DelJobAsync(job.JobId); var message = new JobMessage <T>(job); using var scope = _serviceProvider.CreateScope(); var mediator = scope.ServiceProvider.GetRequiredService <IMediator>(); await mediator.Send(message); } catch (Exception e) { _logger.LogError(e, $"ConsumeReadyJob Error; Topic:{typeof(T).Name}"); await Task.Delay(1000); } } }
public override Boolean OnKeyMenu(GameObject go) { if (base.OnKeyMenu(go) && !_hidingHud && ButtonGroupState.ActiveGroup == CommandGroupButton) { if (ReadyQueue.Count > 1) { Int32 num = ReadyQueue[0]; ReadyQueue.RemoveAt(0); ReadyQueue.Add(num); using (List <Int32> .Enumerator enumerator = ReadyQueue.GetEnumerator()) { while (enumerator.MoveNext()) { Int32 current = enumerator.Current; if (!InputFinishList.Contains(current) && !_unconsciousStateList.Contains(current) && current != CurrentPlayerIndex) { if (ReadyQueue.IndexOf(current) > 0) { ReadyQueue.Remove(current); ReadyQueue.Insert(0, current); } SwitchPlayer(current); break; } } } } else if (ReadyQueue.Count == 1) { SwitchPlayer(ReadyQueue[0]); } } return(true); }
/// <summary> /// This function will check the process queue for ready queue. This will be common to all the algorithms, except RR. /// <returns>a boolean value indicating whether there is any process in ready queue</returns> /// </summary> /// <remarks>Need to override it in RR.</remarks> public bool CheckProcessQueue() { bool _bRtnVal = false; ReadyQueue.RemoveAll(x => x.IsCompleted); _bRtnVal = ReadyQueue.Any(x => !x.IsCompleted); return(_bRtnVal); }
public void AddPlayerToReady(Int32 playerId) { if (_unconsciousStateList.Contains(playerId)) { return; } ReadyQueue.Add(playerId); _partyDetail.GetCharacter(playerId).ATBBlink = true; }
public Cpu(Ram ram) { Ram = ram; ReadyQueue = new ReadyQueue(PriorityCount); DeviceReadQueue = new DeviceQueue(); DeviceWriteQueue = new DeviceQueue(); Locks = Enumerable.Range(1, LockCount).Select(x => (DeviceId)(x + Devices.Locks)).Select(x => new Lock(x)).ToArray(); Events = Enumerable.Range(1, EventCount).Select(x => (DeviceId)(x + Devices.Events)).Select(x => new Event(x)).ToArray(); SleepTimer = new CpuSleepTimer(); _processes = new Dictionary<uint, ProcessContextBlock>(); _operations = OpCodeMetaInformationBuilder.GetMetaInformation().ToDictionary(x => x.OpCode, OpCodeMetaInformationBuilder.BuildOperation); IdleProcess = new ProcessContextBlock { Id = 1, }; InputDevice = new TerminalInputDevice(); }
public async Task DeliveryToReadyQueue() { var jobPool = new JobPool <T>(); var bucket = new Bucket(); var readyQueue = new ReadyQueue <T>(); var topic = typeof(T).Name; while (true) { try { // todo load batchno from config options var jobids = await bucket.GetExpireJobsAsync(topic, 10); if (jobids == null || jobids.Length == 0) { await Task.Delay(500); continue; } foreach (var jobid in jobids) { var job = await jobPool.GetJobAsync(jobid); if (job != null) { //add to ready queue await readyQueue.PushToReadyQueue(topic, job); } await bucket.RemoveJobAsync(topic, jobid); } } catch (Exception e) { _logger.LogError(e, $"DeliveryToReadyQueue Error;Topic:{topic}"); await Task.Delay(1000); } } }
/// <summary> /// Sort the base queue based on arrival time for this algorithm /// </summary> public override void SortProcessQueue() { ReadyQueue.Sort((x, y) => { if ((x.Priority < y.Priority) || (x.Priority.Equals(y.Priority) && x.Burst < y.Burst)) { return(-1); } else { return(0); } }); base.SortProcessQueue(); }
/// <summary> /// Executes the process. This function will show the grant chart on the console screen as the execution goes on. /// </summary> protected Process ExecuteProcess(Process currentProcess) { currentProcess.WaitTime += (Counter - currentProcess.EnterTime); if (!IsRR) { ProcessTotal++; } if (!IsRR || (IsRR && currentProcess.Burst < Quanta)) { if (currentProcess.Length >= currentProcess.Burst) { Counter += currentProcess.Burst; CPURunningTime += currentProcess.Burst; currentProcess.Length -= currentProcess.Burst; currentProcess.RunningTime += currentProcess.Burst; currentProcess.ActualCPUBurst = currentProcess.Burst; currentProcess.ExpectedCPUBurst = (Alpha * currentProcess.ActualCPUBurst) + ((1 - Alpha) * currentProcess.ExpectedCPUBurst); currentProcess.EnterTime = Counter + IOTime; if (currentProcess.Length <= 0) { currentProcess.IsCompleted = true; } currentProcess.Burst = MeanRandomNumber(CPUBurstTimes[ReadyQueue.IndexOf(currentProcess)]); } else { Counter += currentProcess.Length; CPURunningTime += currentProcess.Length; currentProcess.RunningTime += currentProcess.Length; currentProcess.Length = 0; currentProcess.IsCompleted = true; currentProcess.TurnAroundTime = currentProcess.RunningTime + currentProcess.WaitTime; TotalTurnAroundTime += currentProcess.TurnAroundTime; TotalWaitTime += currentProcess.WaitTime; } } else { CPURunningTime += Quanta; Counter += Quanta; currentProcess.Burst -= Quanta; currentProcess.Length -= Quanta; currentProcess.RunningTime += Quanta; currentProcess.EnterTime = Counter; } return(currentProcess); }
/// <summary> /// This is entry point of the execution of the algorithm from outside the world. /// </summary> public override void ExecuteAlgorithm() { Console.WriteLine("Gantt Chart"); Console.WriteLine("_________________________________________________________________"); double _tat = 0; double _wt = 0; while (ReadyQueue.Count > 0) { Process _tempProcess = ReadyQueue[0] as Process; double _originalBurst = _tempProcess.Burst; if (_tempProcess.RRStart.Equals(0) && _tempProcess.RRBurst.Equals(0)) { _tempProcess.RRStart = Counter; } if (_tempProcess.RRBurst.Equals(0)) { _tempProcess.RRBurst = _originalBurst; } _tempProcess.Burst = Quanta; ExecuteProcess(_tempProcess); _tempProcess.Burst = _originalBurst - Quanta; if (_tempProcess.Burst <= 0) { _tempProcess.IsCompleted = true; _tempProcess.Burst = _tempProcess.RRBurst; _tempProcess.StartTime = _tempProcess.RRStart; _tempProcess.EndTime = Counter; _tempProcess.WaitTime = _tempProcess.TurnAroundTime - _tempProcess.Burst; PreviousProcessEndTime = _tempProcess.EndTime; _tat += _tempProcess.TurnAroundTime; _wt += _tempProcess.WaitTime; ReadyQueue.Remove(_tempProcess); CompletedQueue.Add(_tempProcess); } else { PreviousProcessEndTime = Counter; ReadyQueue = ReadyQueue.Skip(1).Concat(ReadyQueue.Take(1)).ToList(); } } TotalTurnAroundTime = _tat; TotalWaitTime = _wt; Console.WriteLine("_________________________________________________________________"); }
void HandleReadyPayload(DiscordApiData payload, DiscordApiData data) { int port = data.GetInteger("port").Value; int ssrc = data.GetInteger("ssrc").Value; IList <DiscordApiData> modesArray = data.GetArray("modes"); string[] modes = new string[modesArray.Count]; for (int i = 0; i < modes.Length; i++) { modes[i] = modesArray[i].ToString(); } log.LogVerbose($"[Ready] ssrc = {ssrc}, port = {port}"); // Notify ReadyQueue.Add(new VoiceReadyEventArgs(port, ssrc, modes)); }
/// <summary> /// This is entry point of the execution of the algorithm from outside the world. /// </summary> public override void ExecuteAlgorithm() { Console.WriteLine("_________________________________________________________________"); while (true) { int _tempProcessId = -1; int _minEnter = Counter + 1; //Process entering later than Clock is under IO or waiting. bool _isDone = ReadyQueue.All(x => x.IsCompleted); for (int _index = 0; _index < ReadyQueue.Count; _index++) { if (ReadyQueue[_index].IsStarted && !ReadyQueue[_index].IsCompleted && ReadyQueue[_index].EnterTime < _minEnter) { _tempProcessId = _index; _minEnter = ReadyQueue[_index].EnterTime; } } if (_tempProcessId >= 0) { Process _executedProcess = ExecuteProcess(ReadyQueue[_tempProcessId]); if (_executedProcess.IsCompleted) { CompletedQueue.Add(_executedProcess); } } else { if (!_isDone) { Counter += 5; CPUWaitingTime += 5; } else { break; } } } CompletedQueue = CompletedQueue.OrderBy(x => x.Name).ToList(); Console.WriteLine("_________________________________________________________________"); }
/// <summary> /// This is entry point of the execution of the algorithm from outside the world. /// </summary> public override void ExecuteAlgorithm() { Console.WriteLine("_________________________________________________________________"); while (true) { int _tempProcessId = -1; int _shortest = int.MaxValue; bool _isDone = ReadyQueue.All(x => x.IsCompleted); for (int _index = 0; _index < ReadyQueue.Count; _index++) { if (ReadyQueue[_index].IsStarted && !ReadyQueue[_index].IsCompleted && ReadyQueue[_index].ExpectedCPUBurst < _shortest && ReadyQueue[_index].EnterTime < Counter) { _tempProcessId = _index; _shortest = ReadyQueue[_index].Burst; } } if (_tempProcessId >= 0) { Process _executedProcess = ExecuteProcess(ReadyQueue[_tempProcessId]); if (_executedProcess.IsCompleted) { CompletedQueue.Add(_executedProcess); } } else { if (!_isDone) { Counter += 5; CPUWaitingTime += 5; } else { break; } } } CompletedQueue = CompletedQueue.OrderBy(x => x.Name).ToList(); Console.WriteLine("_________________________________________________________________"); }
public void RemovePlayerFromAction(Int32 btlId, Boolean isNeedToClearCommand) { Int32 num = 0; while (1 << num != btlId) { ++num; } if (InputFinishList.Contains(num) && isNeedToClearCommand) { InputFinishList.Remove(num); } if (!ReadyQueue.Contains(num) || !isNeedToClearCommand) { return; } ReadyQueue.Remove(num); }
/// <summary> /// This is entry point of the execution of the algorithm from outside the world. /// </summary> public override void ExecuteAlgorithm() { Console.WriteLine("_________________________________________________________________"); while (true) { int _processId = -1; bool _isDone = ReadyQueue.All(x => x.IsCompleted); for (int _index = 0; _index < ReadyQueue.Count; _index++) { if (!ReadyQueue[_index].IsCompleted && ReadyQueue[_index].EnterTime < Counter) { Counter += ContextSwitch; CPUWaitingTime += ContextSwitch; _processId = _index; Process _executedProcess = ExecuteProcess(ReadyQueue[_index]); if (_executedProcess.IsCompleted) { CompletedQueue.Add(_executedProcess); } } } if (_processId.Equals(-1)) { if (!_isDone) { Counter += 5; CPUWaitingTime += 5; } else { break; } } } CompletedQueue = CompletedQueue.OrderBy(x => x.Name).ToList(); Console.WriteLine("_________________________________________________________________"); }
/// <summary> /// Sort the base queue based on arrival time for this algorithm /// </summary> public override void SortProcessQueue() { ReadyQueue = ReadyQueue.OrderBy(x => x.ArrivalTime).ToList(); base.SortProcessQueue(); }
private void UpdatePlayer() { _blinkAlphaCounter += RealTime.deltaTime * 3f; _blinkAlphaCounter = _blinkAlphaCounter <= 2.0 ? _blinkAlphaCounter : 0.0f; Single alpha = _blinkAlphaCounter > 1.0 ? 2f - _blinkAlphaCounter : _blinkAlphaCounter; if (!_commandEnable) { return; } foreach (UI.PanelParty.Character character in _partyDetail.Characters.Entries) { if (character.PlayerId == -1) { continue; } BattleUnit player = FF9StateSystem.Battle.FF9Battle.GetUnit(character.PlayerId); if ((player.IsUnderStatus(BattleStatus.Confuse) || player.IsUnderStatus(BattleStatus.Berserk)) && character.ATBBlink) { character.ATBBlink = false; } if (IsEnableInput(player) && !_isAutoAttack) { if (character.ATBBlink) { character.ATBBar.Foreground.Widget.alpha = alpha; } if (character.TranceBlink && player.HasTrance) { character.TranceBar.Foreground.Widget.alpha = alpha; } } else { if (character.ATBBlink) { character.ATBBar.Foreground.Widget.alpha = 1f; character.ATBBar.Foreground.Highlight.Sprite.alpha = 0.0f; } if (character.TranceBlink && player.HasTrance) { character.TranceBar.Foreground.Widget.alpha = 1f; character.TranceBar.Foreground.Highlight.Sprite.alpha = 0.0f; } } } YMenu_ManagerHpMp(); CheckPlayerState(); DisplayPartyRealtime(); if (TargetPanel.activeSelf) { DisplayTarget(); _statusPanel.DisplayStatusRealtime(_matchBattleIdPlayerList); } ManagerTarget(); ManagerInfo(); if (CurrentPlayerIndex > -1) { BattleUnit unit = FF9StateSystem.Battle.FF9Battle.GetUnit(CurrentPlayerIndex); if (ButtonGroupState.ActiveGroup == CommandGroupButton && _isTranceMenu) { _tranceColorCounter = (_tranceColorCounter + 1) % TranceTextColor.Length; _commandPanel.SetCaptionColor(TranceTextColor[_tranceColorCounter]); } if (!IsEnableInput(unit)) { SetIdle(); return; } if (TargetPanel.activeSelf) { if (!ManageTargetCommand()) { return; } } else if (AbilityPanel.activeSelf || ItemPanel.activeSelf) { if (AbilityPanel.activeSelf) { DisplayAbilityRealTime(); } if (ItemPanel.activeSelf) { DisplayItemRealTime(); } if ((Int32)_currentCommandId == 31 && (!_magicSwordCond.IsViviExist || _magicSwordCond.IsViviDead || _magicSwordCond.IsSteinerMini)) { FF9Sfx.FF9SFX_Play(101); ResetToReady(); return; } if (!_isTranceMenu && unit.IsUnderAnyStatus(BattleStatus.Trance)) { FF9Sfx.FF9SFX_Play(101); ResetToReady(); return; } } } if (ReadyQueue.Count <= 0 || CurrentPlayerIndex != -1) { return; } for (Int32 index = ReadyQueue.Count - 1; index >= 0; --index) { if (!_unconsciousStateList.Contains(ReadyQueue[index])) { continue; } BattleUnit unit = FF9StateSystem.Battle.FF9Battle.GetUnit(ReadyQueue[index]); Boolean needToClearCommand = unit.IsUnderStatus(BattleStatus.CmdCancel); RemovePlayerFromAction(unit.Id, needToClearCommand); } using (List <Int32> .Enumerator enumerator = ReadyQueue.GetEnumerator()) { while (enumerator.MoveNext()) { Int32 current = enumerator.Current; if (InputFinishList.Contains(current) || _unconsciousStateList.Contains(current)) { continue; } if (_isAutoAttack) { SendAutoAttackCommand(current); break; } SwitchPlayer(current); break; } } }