An execution unit represents one logical thread of Triceps. In some special cases more that one unit per actual thread may be useful, but never one unit shared between threads.
A unit is created as:
$myUnit = Triceps::Unit->new("name") or die "$!";
The name argument as usual is used for later debugging, and by convention should be the same as the name of the unite variable ("myUnit" in this case). The name can also be changed later:
$myUnit->setName("newName");
It returns no value. Though in practice there is no good reason for it, and this call will likely be removed in the future. The name can be received back:
$name = $myUnit->getName();
Also, as usual, the variable $myName here contains a reference to the actual unit object, and two references can be compared, whether they refer to the same object:
$result = $unit1->same($unit2);
The rowops are enqueued with the calls:
$unit->call($rowop, ...) or die "$!"; $unit->fork($rowop, ...) or die "$!"; $unit->schedule($rowop, ...) or die "$!";
Also there is a call that selects the enqueueing mode by argument:
$unit->enqueque($mode, $rowop, ...) or die "$!";
Multiple rowops can be specified as arguments. Calling these functions with multiple arguments produces the same result as doing multiple calls with one argument at a time. Not only rowops but also trays (to be discussed later) of rowops can be used as arguments.
The mode for enqueue() is one of either Triceps constants
&Triceps::EM_CALL &Triceps::EM_FORK &Triceps::EM_SCHEDULE
or the matching strings "EM_CALL", "EM_FORK", "EM_SCHEDULE". As usual, the constant form is more efficient. There are calls to convert between the constant and string representations:
$string = &Triceps::emString($value); $value = &Triceps::stringEm($string);
As usual, if the value can not be translated they return undef.
The frame marks for looping are created as their own class:
$mark = Triceps::FrameMark->new("name") or die "$!";
The name can be received back from the mark:
$name = $mark->getName();
Other than that, the frame marks are completely opaque, and can be used only for the loop scheduling. Not even the same() method is supported for them at the moment, though it probably will be in the future. The mark gets set and used as:
$unit->setMark($mark); $unit->loopAt($mark, $rowop, ...) or die "$!";
The rowop arguments of the loopAt() are the same as for the other enqueueing functions.
The methods for creation of labels have been already discussed. There also are similar methods for creation of tables and trays that will be discussed later:
$label = $unit->makeDummyLabel($rowType, "name") or die "$!"; $label = $unit->makeLabel($rowType, "name", $clearSub, $execSub, @args) or die "$!"; $table = $unit->makeTable($tableType, $endMode, "name") or die "$!"; $tray = $unit->makeTray(@rowops) or die "$!";
The unit can be checked for the emptiness of its queues:
$result = $unit->empty();
The functions for execution are:
$unit->callNext(); $unit->drainFrame();
The callNext() takes one label from the top stack frame queue and calls it. If the innermost frame happens to be empty, it does nothing. The drainFrame() calls the rowops from the top stack frame until it becomes empty. This includes any rowops that may be created and enqueued as part of the execution of the previous rowops.
A typical way of processing the incoming rowops in a loop is:
$stop = 0; while (!$stop) { $rowop = readRowop(); # some user-defined function $unit->schedule($rowop); $unit->drainFrame(); }
All the unit's labels get cleared with the call
$unit->clearLabels();
To not forget calling it, a separate clearing trigger object can be created:
my $clearUnit = $unit->makeClearingTrigger();
The variable $clearUnit would normally be a global (in a thread) variable. Don't copy the reference to the other variables! Then when the thread completes and the global variables get destroyed, the trigger object will be also destroyed, and will trigger the clearing of the unit's labels, thus breaking up any reference loops and allowing to destroy the bits and pieces.
The only item left is the tracers, and they will be described in a separate post.
No comments:
Post a Comment