コード例 #1
0
ファイル: Manager.cs プロジェクト: usamasubhani/ccube
 public string OnePlayerArrived(Player p1)
 {
     if (QueueIsEmpty())
     {
         WaitingList.Enqueue(p1);
         return("Player added in queue.");
     }
     else if (!QueueIsEmpty())
     {
         if (!AllTablesBusy())
         {
             Game anewGame = new Game();
             anewGame.Player1   = Manager.WaitingList.Dequeue();
             anewGame.Player2   = p1;
             anewGame.TableName = Manager.getTable();
             Manager.BusyTable();
             Manager.GamesList.Add(anewGame);
         }
         else if (AllTablesBusy())
         {
             WaitingList.Enqueue(p1);
         }
         return("All Tables Busy. Player Added in queue");
     }
     else
     {
         return("ERROR!");
     }
 }
コード例 #2
0
        public void Initialize()
        {
            foreach (Job j in Tasks)
            {
                j.Reset();
                WaitingList.Enqueue(j);
            }

            CalcSeparation();
        }
コード例 #3
0
        //TODO: Does this work correctly with an empty taskset?
        /// <summary>
        /// This method executes the current event if is set.
        /// It also sets the upcoming event based on the readylist/waiting list.
        /// </summary>
        /// <param name="debug">Indicates if the ExecutionTrace should be built.</param>
        public void TriggerEvent(bool debug)
        {
            int next = Int32.MaxValue;

            ReleaseTasks(Event.Cycle);

            if (Current == null)
            {
                if (ReadyList.Count() > 0)
                {
                    if ((Event.Cycle % Hyperperiod) == 0)
                    {
                        int offset = Separation[ReadyList.Peek().Cil];
                        next = Event.Cycle + offset;
                    }
                    else
                    {
                        Current = ReadyList.Dequeue();
                        next    = Current.NextEvent(Event.Cycle, MacroTick);
                    }
                }
                else if (WaitingList.Count() > 0)
                {
                    next = WaitingList.Peek().Release;
                }
            }
            else
            {
                bool finalExecutionSlice = Current.FinalEvent(MacroTick);
                Current.Execute(Event.Cycle, debug, MacroTick);
                next = Current.NextEvent(Event.Cycle, MacroTick);
                int offset = 0;

                if (ReadyList.Count() > 0)
                {
                    Job possibleJob = ReadyList.Peek();
                    if (possibleJob.Cil != Current.Cil)
                    {
                        offset = Separation[possibleJob.Cil];
                    }
                    if (finalExecutionSlice)
                    {
                        WaitingList.Enqueue(Current);
                        Current = null;
                        next    = Event.Cycle + offset;
                    }
                    else if ((possibleJob.PriorityDeadline + offset) < Current.PriorityDeadline)
                    {
                        ReadyList.Enqueue(Current);
                        Current = null;
                        next    = Event.Cycle + offset;
                    }
                }
                else
                {
                    if (finalExecutionSlice)
                    {
                        WaitingList.Enqueue(Current);
                        Current = null;

                        foreach (var item in Separation)
                        {
                            if (offset < item.Value)
                            {
                                offset = item.Value;
                            }
                        }
                        next = Event.Cycle + offset;
                    }
                }



                ReleaseTasks(Event.Cycle);
            }
            Event.Cycle = next;
        }