コード例 #1
0
 public Scheduler()
 {
     this.queueCount = 0;
     this.holdCount  = 0;
     this.blocks     = new TaskControlBlock[NUMBER_OF_IDS];
     this.list       = null;
     this.currentTCB = null;
     this.currentId  = 0;//check this
 }
コード例 #2
0
        /**
         * Add the specified packet to the end of the worklist used by the task
         * associated with the packet and make the task runnable if it is currently
         * suspended.
         * #param {Packet} packet the packet to add
         */
        public TaskControlBlock queue(Packet packet)
        {
            TaskControlBlock t = this.blocks[packet.id];

            if (t == null)
            {
                return(t);
            }
            this.queueCount++;
            packet.link = null;
            packet.id   = this.currentId;
            return(t.checkPriorityAdd(this.currentTCB, packet));
        }
コード例 #3
0
 public TaskControlBlock(TaskControlBlock link, int id, int priority, Packet queue, Task task)
 {
     this.link     = link;
     this.id       = id;
     this.priority = priority;
     this.queue    = queue;
     this.task     = task;
     if (queue == null)
     {
         this.state = States.SUSPENDED;
     }
     else
     {
         this.state = States.SUSPENDED_RUNNABLE;
     }
 }
コード例 #4
0
 /**
  * Execute the tasks managed by this scheduler.
  */
 public void schedule()
 {
     this.currentTCB = this.list;
     while (this.currentTCB != null)
     {
         if (this.currentTCB.isHeldOrSuspended())
         {
             this.currentTCB = this.currentTCB.link;
         }
         else
         {
             this.currentId  = this.currentTCB.id;
             this.currentTCB = this.currentTCB.run();
         }
     }
 }
コード例 #5
0
 /**
  * Adds a packet to the worklist of this block's task, marks this as runnable if
  * necessary, and returns the next runnable object to run (the one
  * with the highest priority).
  */
 public TaskControlBlock checkPriorityAdd(TaskControlBlock task, Packet packet)
 {
     if (this.queue == null)
     {
         this.queue = packet;
         this.markAsRunnable();
         if (this.priority > task.priority)
         {
             return(this);
         }
     }
     else
     {
         this.queue = packet.addTo(this.queue);
     }
     return(task);
 }
コード例 #6
0
        /**
         * Release a task that is currently blocked and return the next block to run.
         * #param {int} id the id of the task to suspend
         */
        public TaskControlBlock release(int id)
        {
            TaskControlBlock tcb = this.blocks[id];

            if (tcb == null)
            {
                return(tcb);
            }
            tcb.markAsNotHeld();
            if (tcb.priority > this.currentTCB.priority)
            {
                return(tcb);
            }
            else
            {
                return(this.currentTCB);
            }
        }
コード例 #7
0
 /**
  * Add the specified task to this scheduler.
  * @param {int} id the identity of the task
  * @param {int} priority the task's priority
  * @param {Packet} queue the queue of work to be processed by the task
  * @param {Task} task the task to add
  */
 public void addTask(int id, int priority, Packet queue, Task task)
 {
     this.currentTCB = new TaskControlBlock(this.list, id, priority, queue, task);
     this.list       = this.currentTCB;
     this.blocks[id] = this.currentTCB;
 }