../../AspectXLib/RealTime/PassiveToSporadic/aspects/PassiveToSporadic.axactivate() method
of class Task. These calls are invoked from the function
scheduler() which acts as a source of sporadic triggers.
The aspect replaces the original activate() function defined in the passive class
by the a new function _activate(). This function contain an infinite loop.
On every cycle the condition variable trigger is checked. If
it has a zero value the execution of the thread is suspended until the value of the
trigger variable is non-zero. On release the original function
activate() is called. At the end of every cycle the value of the trigger is set back to
zero.
Since the trigger acts act as a condition variable it has to be protected
against access by more then one thread at the same time. The protection
if this critical section is implemented using mutex object.
The aspect also replaces the body of the original scheduler() function
by function _scheduler().
It creates and runs the thread of the Task object. It also emulates
two sporadic events by setting up the trigger to non-zero values.
The activation code uses synchronization primitives provided by the POSIX standard.
Pointcuts | |
| unit | targetInitializationUnit |
|
Points to the unit that contains main() method | |
| block | targetSchedulerMethodBody |
| Points to the body of the function scheduler() | |
| class | targetTaskClassDeclaration |
|
Points to the target class to which the declaration of the _activate() method
should be added | |
| unit | targetTaskClassDefinition |
|
Points to the target unit where is defined class Task | |
Advices | |
| add | addSynchronizationDefinition |
|
Adds declaration and initialization of three variables
needed to implement the mutual exclusive access
to the condition variable trigger | |
| add | addSynchronizationDeclaration |
|
Adds external declaration of three variables
needed to implement the mutual exclusive access
to the condition variable trigger | |
| add | addSporadicActivateDeclaraion |
|
Add declaration of _activate() method to the class declaration | |
| add | addSporadicActivateDefinition |
|
Add definition of _activate() method to class definition files | |
| add | addActivationHelperFunctions |
|
Adds definition of helper a function
_activate() to tha main program unit | |
| add | addIncludesToMain |
|
Add the #include "main | |
| around | replaceSchedulerBody |
|
Replaces the body of schedule() function | |
unit that contains main() method. In srcML, a unit is
a source file (a definition file, a declaration file, or
an inline file). The pointcut is restricted to include only those units that contain
function whose full name is 'main'.
scheduler().
_activate() method
should be added. The class that must be modified is identified by its full name: Task.
Task.
Triplet: unit add declaration
trigger.
This advice has to precede other advices that modify code
in the main unit.
Refers to global pointcut: unit targetInitializationUnit
Triplet: unit add definition
trigger.
Refers to global pointcut: unit targetTaskClassDefinition
Triplet: class add declaration
_activate() method to the class declaration.
This method is to be called as a POSIX thread. Therefore its
return value must be a pointer (void *) and must have
one untyped pointer as a parameter.
Refers to global pointcut: class targetTaskClassDeclaration
Triplet: unit add definition
_activate() method to class definition files.
The method body contains an infinite loop. The activate() method of the
same class is called if the condition variable has non-zero value.
Refers to global pointcut: unit targetTaskClassDefinition
Triplet: unit add definition
_activate() to tha main program unit. This function
activates the thread of a sporadic object. It
passes the call to the _activate() method of the object
task - an instance of class Task.
Helper functions are used because POSIX function
pthread_create() does not allow
to use C++ method
as a parameter - only C functions are accepted.
Refers to global pointcut: unit targetInitializationUnit
Triplet: unit add include
#include "main.h" preprocessor instruction.
Header file main.h contains signature of function
_activate() which is inserted to the main module. Since
function is woven at the end of the file its declarations have to
be inserted at the beginning of the unit using the header file.
Refers to global pointcut: unit targetInitializationUnit
Triplet: block around codeFragment
schedule() function.
It inserts the code that
initialize the thread of an active object, emulates
two sporadic events by setting the trigger
variable to non-zero value, and suspend the
execution of the main thread.
he threads are executed using helper functions
_activate()
that passes the call to the _activate() method
defined in the class Task.
Refers to global pointcut: block targetSchedulerMethodBody