Entry Aspect
[Synchronization Group]

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

Aspect Description

This aspect inserts synchronization code into the base code to implement methods as entries (in Ada95 sense of word). Synchronization code is code that protects access to certain code segments. In this example synchronization code provides protection against simultaneous access to a class method by more than one thread of execution.

A protected entry is guaranteed to execute in mutual exclusion and is guarded by a boolean expression (called a barrier). If this barrier evaluates to false when the entry call is made, the calling thread is suspended until the barrier evaluates to true and no other threads are active inside the protected object. Hence protected entry calls can be used to implement condition synchronization.

This sample aspect adds synchronization code to the body of the method that has to be protected. It uses a value of trigger as a barrier. The barrier is accessed in mutual exclusion. It uses mutex object to protect the method (entry) against multiple access to the method and condition variable condvar to control the access to the barrier.

The activation code uses synchronization primitives provided by the POSIX standard.
Author:
A. Pasetti, O. Rohlik
See also:
Synchronization
PassiveToSporadic

Pointcuts

classtargetClassDeclaration
  Points to the target class declaration
unittargetClassDefinition
  Points to the target unit where method of the given class are defined
unittargetClassUnit
  Points to the target unit where class identified by pointcut targetClassDeclaration is declared
functiontargetSynchronizedFunction
  Point to the function definition that has to be synchronized
unittargetInitializationUnit
  Points to the unit that contains main() method

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
addaddInclude
  Add the #include <pthread
beginatBegin
  Inserts the code that locks the access to the method body by acquiring the mutex
endatEnd
  Inserts the code that release the access to the method body by releasing the mutex
replaceguardConditionChange
  Inserts the code to the main() function that changes the barrier by setting the trigger variable to non-zero value

Pointcut Documentation

class targetClassDeclaration (source)
Points to the target class declaration. The class is identified by its full name: UniqueResource.
unit targetClassDefinition (source)
Points to the target unit where method of the given class are defined. The class if specified by a pointcut targetClassDeclaration.
unit targetClassUnit (source)
Points to the target unit where class identified by pointcut targetClassDeclaration is declared.
function targetSynchronizedFunction (source)
Point to the function definition that has to be synchronized. The function is identified by its full name: UniqueResource::activate()
unit targetInitializationUnit (source)
Points to the unit that contains main() method. The pointcut is restricted to include only those units that contain function whose full name is 'main'.

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 targetClassDefinition

add addSynchronizationDeclaration (source)

Triplet: unit add declaration

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

Refers to global pointcut: unit targetInitializationUnit

add addInclude (source)

Triplet: unit add include

Add the #include <pthread.h> preprocessor instruction. Header file pthread.h contain declaration of methods and data types implementing mutual exclusive access policy according to the POSIX standard.

Refers to global pointcut: unit targetClassDefinition

begin atBegin (source)

Triplet: function begin codeFragment

Inserts the code that locks the access to the method body by acquiring the mutex. The code is inserted at the very beginning of the target method.

Refers to global pointcut: function targetSynchronizedFunction

end atEnd (source)

Triplet: function end codeFragment

Inserts the code that release the access to the method body by releasing the mutex. The code is inserted at the very end of the target method.

Refers to global pointcut: function targetSynchronizedFunction

replace guardConditionChange (source)

Triplet: comment replace codeFragment

Inserts the code to the main() function that changes the barrier by setting the trigger variable to non-zero value. This has to be done in mutual exclusion. Note that in this example the barrier is the condition (!trigger).

Local Pointcut: comment (source)