Пример #1
0
        public static bool runRichards()
        {
            Scheduler scheduler = new Scheduler();
            scheduler.addIdleTask(ID_IDLE, 0, null, COUNT);
            Packet queue = new Packet(null, ID_WORKER, KIND_WORK);
            queue = new Packet(queue, ID_WORKER, KIND_WORK);
            scheduler.addWorkerTask(ID_WORKER, 1000, queue);

            queue = new Packet(null, ID_DEVICE_A, KIND_DEVICE);
            queue = new Packet(queue, ID_DEVICE_A, KIND_DEVICE);
            queue = new Packet(queue, ID_DEVICE_A, KIND_DEVICE);
            scheduler.addHandlerTask(ID_HANDLER_A, 2000, queue);

            queue = new Packet(null, ID_DEVICE_B, KIND_DEVICE);
            queue = new Packet(queue, ID_DEVICE_B, KIND_DEVICE);
            queue = new Packet(queue, ID_DEVICE_B, KIND_DEVICE);
            scheduler.addHandlerTask(ID_HANDLER_B, 3000, queue);

            scheduler.addDeviceTask(ID_DEVICE_A, 4000, null);
            scheduler.addDeviceTask(ID_DEVICE_B, 5000, null);
            scheduler.schedule();

            return ((scheduler.queueCount == EXPECTED_QUEUE_COUNT)
                && (scheduler.holdCount == EXPECTED_HOLD_COUNT));
        }
Пример #2
0
      TaskControlBlock run(Packet packet)
 {
     if (packet == null)
     {
         return this.scheduler.suspendCurrent();
     }
     else
     {
         if (this.v1 == Support.ID_HANDLER_A)
         {
             this.v1 = Support.ID_HANDLER_B;
         }
         else
         {
             this.v1 = Support.ID_HANDLER_A;
         }
         packet.id = this.v1;
         packet.a1 = 0;
         for (int i = 0; i < Support.DATA_SIZE; i++)
         {
             this._v2++;
             if (this._v2 > 26) this._v2 = 1;
             packet.a2[i] = this._v2;
         }
         return this.scheduler.queue(packet);
     }
 }
Пример #3
0
      TaskControlBlock run(Packet packet)
 {
     if (packet == null)
     {
         if (_v1 == null) return this.scheduler.suspendCurrent();
         Packet v = _v1;
         _v1 = null;
         return this.scheduler.queue(v);
     }
     else
     {
         _v1 = packet;
         return this.scheduler.holdCurrent();
     }
 }
Пример #4
0
 public DeviceTask(Scheduler scheduler)
 {
     this.scheduler = scheduler;
     _v1 = null;
 }
Пример #5
0
     TaskControlBlock run(Packet packet)
 {
     this._count--;
     if (this._count == 0) return this.scheduler.holdCurrent();
     if ((this._v1 & 1) == 0)
     {
         this._v1 = this._v1 >> 1;
         return this.scheduler.release(Support.ID_DEVICE_A);
     }
     else
     {
         this._v1 = (this._v1 >> 1) ^ 0xD008;
         return this.scheduler.release(Support.ID_DEVICE_B);
     }
 }
Пример #6
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;
 }
Пример #7
0
 /**
  * Add a work 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
  */
 public void addWorkerTask(int id, int priority, Packet queue)
 {
     this.addTask(id, priority, queue,
                  new WorkerTask(this, Support.ID_HANDLER_A, 0));
 }
Пример #8
0
 public Packet(Packet link, int id, int kind)
 {
     this.link = link;
     this.id = id;
     this.kind = kind;
     this.a1 = 0;
     this.a2 = new int[Support.DATA_SIZE];
 }
Пример #9
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);
 }
Пример #10
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;
 }
Пример #11
0
 /**
  * Add the specified task and mark it as running.
  * @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 addRunningTask(int id, int priority, Packet queue, Task task)
 {
     this.addTask(id, priority, queue, task);
     this.currentTcb.setRunning();
 }
Пример #12
0
 /**
  * Add a handler 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
  */
 public void addDeviceTask(int id, int priority, Packet queue)
 {
     this.addTask(id, priority, queue, new DeviceTask(this));
 }
Пример #13
0
 /**
  * Add a handler 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
  */
 public void addHandlerTask(int id, int priority, Packet queue)
 {
     this.addTask(id, priority, queue, new HandlerTask(this));
 }
Пример #14
0
 public HandlerTask(Scheduler scheduler)
 {
     this.scheduler = scheduler;
     this.v1 = null;
     this.v2 = null;
 }
Пример #15
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 = Support.STATE_SUSPENDED;
     }
     else
     {
         this.state = Support.STATE_SUSPENDED_RUNNABLE;
     }
 }
Пример #16
0
      TaskControlBlock run(Packet packet)
 {
     if (packet != null)
     {
         if (packet.kind == Support.KIND_WORK)
         {
             this.v1 = packet.addTo(this.v1);
         }
         else
         {
             this.v2 = packet.addTo(this.v2);
         }
     }
     if (this.v1 != null)
     {
         int count = this.v1.a1;
         Packet v;
         if (count < Support.DATA_SIZE)
         {
             if (this.v2 != null)
             {
                 v = this.v2;
                 this.v2 = this.v2.link;
                 v.a1 = this.v1.a2[count];
                 this.v1.a1 = count + 1;
                 return this.scheduler.queue(v);
             }
         }
         else
         {
             v = this.v1;
             this.v1 = this.v1.link;
             return this.scheduler.queue(v);
         }
     }
     return this.scheduler.suspendCurrent();
 }
Пример #17
0
        /**
         * Runs this task, if it is ready to be run, and returns the next task to run.
         */
        public TaskControlBlock run()
        {
            Packet packet;
#if TRACEIT
             Console.WriteLine("  TCB::run, state = {0}", this.state);
#endif
            if (this.state == Support.STATE_SUSPENDED_RUNNABLE)
            {
                packet = this.queue;
                this.queue = packet.link;
                if (this.queue == null)
                {
                    this.state = Support.STATE_RUNNING;
                }
                else
                {
                    this.state = Support.STATE_RUNNABLE;
                }
#if TRACEIT
                 Console.WriteLine("   State is now {0}", this.state);
#endif
            }
            else
            {
#if TRACEIT
                 Console.WriteLine("  TCB::run, setting packet = Null.");
#endif
                packet = null;
            }
            return this.task.run(packet);
        }
Пример #18
0
 public Packet addTo(Packet queue)
 {
     this.link = null;
     if (queue == null) return this;
     Packet peek;
     Packet next = queue;
     while ((peek = next.link) != null)
         next = peek;
     next.link = this;
     return queue;
 }
Пример #19
0
 /**
  * Add an idle 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 {int} count the number of times to schedule the task
  */
 public void addIdleTask(int id, int priority, Packet queue, int count)
 {
     this.addRunningTask(id, priority, queue,
                         new IdleTask(this, 1, count));
 }