package bench;
interface ISchedulerTask {
Tcb run(Packet packet);
}
/**The Idle task counts how often it is activated ending
* the simulation when the aCount limit is reached.
* Normally it releases either DeviceA or DeviceB.
*/
class IdleTask implements ISchedulerTask {
int v1;
int v2;
Scheduler scheduler;
run(packet) {
v2--;
if (v2 == 0)
return scheduler.holdCurrent;
if ( ( v1 & 1) == 0 )
{
v1 = v1 >> 1;
return scheduler.release(DeviceA);
}
else
{
v1 = (v1 >> 1 ) ^ 0xD008 ;
return scheduler.release(DeviceB);
}
}
}
/**The worker task packs characters into Packets and
* sends them alternately to HandlerA or HandlerB.
*/
class WorkerTask implements ISchedulerTask {
PacketId v1;
int v2;
Scheduler scheduler;
run(packet) {
if (packet == NoPacket)
{
return scheduler.suspendCurrent;
}
else
{
if (v1 == HandlerA)
v1 = HandlerB;
else
v1 = HandlerA;
packet.setId( v1 );
packet.setA1( (byte)(0) );
for (int i=0; i < DataSize; i++)
{
v2++;
if (v2 > 26) v2 = 1;
packet.getA2[i] = byte(int('A') + v2 - 1);
}
return scheduler.queue(packet);
}
}
}
/**The HandlerA task receives Packets from Worker and
* sends the characters they contain to DeviceA task
* one at a time.
* The HandlerB task receives Packets from Worker and
* sends the characters they contain to DeviceB task
* one at a time.
*/
class HandlerTask implements ISchedulerTask {
Packet v1;
Packet v2;
Scheduler scheduler;
run(packet){
if (packet != NoPacket)
{
if (packet.getKind == Work)
v1 = packet.addTo(queue: v1);
else
v2 = packet.addTo(queue: v2);
}
if (v1 != NoPacket)
{
byte count = v1.getA1;
Packet v;
if (count < DataSize )
{
if (v2 != NoPacket )
{
v = v2;
v2 = v2.getLink;
v.setA1( v1.getA2[count] );
v1.setA1( (byte)(count + 1) );
return scheduler.queue(packet: v);
}
}
else
{
v = v1;
v1 = v1.getLink;
return scheduler.queue(v);
}
}
return scheduler.suspendCurrent;
}
}
/**The device task simulates a single character device.
* On receiving a Packet is suspends itself.
* When DeviceA is released by the Idle task it returns the
* packet to HanderA. When DeviceB is released by the Idle
* task it returns the packet to HanderB.
*/
class DeviceTask implements ISchedulerTask {
Packet v1;
Scheduler scheduler;
run(packet){
if (packet == NoPacket)
{
if (v1 == NoPacket)
return scheduler.suspendCurrent;
Packet v = v1;
v1 = NoPacket;
return scheduler.queue(v);
}
else
{
v1 = packet;
if (traceOn) trace( (char)(packet.getA1) );
return scheduler.holdCurrent;
}
}
}
-- DuncanLissett - 02 Sep 2003
| Topic TaskBenchExample . { Edit | Attach | Ref-By | Printable | Diffs | r1.2 | > | r1.1 | More } |
|
Revision r1.2 - 03 Sep 2003 - 18:45 GMT - DanielBonniot Parents: WebHome > CodeExamples |
Copyright © 1999-2003 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding TWiki? Send feedback. |