PassiveToSporadic Aspect
[Activation Group]

This aspect is defined in file: ../../AspectXLib/RealTime/PassiveToSporadic/aspects/PassiveToSporadic.ax

Aspect Description

This sample aspect transforms passive classes into active (sporadic) classes. A passive class is a class whose object instances do not have their own execution thread. An active class is instead a class whose instances have an execution thread associated to them. This apsect demonstrates how to turn a passive class into a sporadic class i.e. a class with its own thread of execution that is triggered by some external entity.

This aspect operates on base code that sporadically calls activate() 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.
Author:
A. Pasetti, O. Rohlik
See also:
PassiveToCyclical
Entry

Pointcuts

unittargetInitializationUnit
  Points to the unit that contains main() method
blocktargetSchedulerMethodBody
 Points to the body of the function scheduler()
classtargetTaskClassDeclaration
  Points to the target class to which the declaration of the _activate() method should be added
unittargetTaskClassDefinition
  Points to the target unit where is defined class Task

Advices

addaddSynchronizationDefinition
  Adds declaration and initialization of three variables needed to implement the mutual exclusive access to the condition variable trigger
addaddSynchronizationDeclaration
  Adds external declaration of three variables needed to implement the mutual exclusive access to the condition variable trigger
addaddSporadicActivateDeclaraion
  Add declaration of _activate() method to the class declaration
addaddSporadicActivateDefinition
  Add definition of _activate() method to class definition files
addaddActivationHelperFunctions
  Adds definition of helper a function _activate() to tha main program unit
addaddIncludesToMain
  Add the #include "main
aroundreplaceSchedulerBody
  Replaces the body of schedule() function

Pointcut Documentation

unit targetInitializationUnit (source)
Points to the 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'.
block targetSchedulerMethodBody (source)
Points to the body of the function scheduler().
class targetTaskClassDeclaration (source)
Points to the target class to which the declaration of the _activate() method should be added. The class that must be modified is identified by its full name: Task.
unit targetTaskClassDefinition (source)
Points to the target unit where is defined class Task.

Advice Documentation

add addSynchronizationDefinition (source)

Triplet: unit add declaration

Adds declaration and initialization of three variables needed to implement the mutual exclusive access to the condition variable trigger.

This advice has to precede other advices that modify code in the main unit.

Refers to global pointcut: unit targetInitializationUnit

add addSynchronizationDeclaration (source)

Triplet: unit add definition

Adds external declaration of three variables needed to implement the mutual exclusive access to the condition variable trigger.

Refers to global pointcut: unit targetTaskClassDefinition

add addSporadicActivateDeclaraion (source)

Triplet: class add declaration

Add declaration of _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

add addSporadicActivateDefinition (source)

Triplet: unit add definition

Add definition of _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

add addActivationHelperFunctions (source)

Triplet: unit add definition

Adds definition of helper a function _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

add addIncludesToMain (source)

Triplet: unit add include

Add the #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

around replaceSchedulerBody (source)

Triplet: block around codeFragment

Replaces the body of 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