../../AspectXLib/RealTime/Synchronization/aspects/Synchronization.axmutex object to lock the
access to the method.
The base code upon which the aspect operates is a small but self-contained application.
The application consists of: one main class that holds the main program;
two task classes (Task1 and Task2) that represent two threads competing
for a shared resource; one resource class (UniqueResource) that represents the shared
resource; one helper class (MicroTime) that encapsulates access to timing services.
The aspect transformation adds synchronization code to method activate in
class UniqueResource. The woven code calls a system function to acquire the
mutex object as soon as the method is entered and releases it when the method is exited.
The activation code uses synchronization primitives provided by the POSIX standard.
Pointcuts | |
| class | targetClassDeclaration |
|
Points to the target class declaration | |
| unit | targetClassUnit |
|
Points to the unit where is declared class identified
by pointcut targetTaskClassDeclaration | |
| function | targetSynchronizedFunction |
|
Point to the definition of function that has to be synchronized | |
| constructor | targetConstructorImplementation |
|
Points to all constructors of the target class | |
Advices | |
| add | addMutexDeclaraion |
|
Add declaration of the mutex object to the class declaration | |
| add | addInclude |
|
Add the #include <pthread | |
| begin | initializeMutex |
|
Adds the initialization of the mutex variable to the constructor | |
| begin | atBegin |
|
Inserts the code that locks the access to the method body
by acquiring the mutex | |
| end | atEnd |
|
Inserts the code that release the access to the method body
by releasing the mutex | |
UniqueResource.
targetTaskClassDeclaration.
UniqueResource::activate()
name subelements. Only the
first subelement is used in this pointcut. However the full name can be also used
to constraint the pointcut:
src:name='UniqueResource::UniqueResource'.
Triplet: class add declaration
mutex object to the class declaration.
It is declared as private since it is only used in
the activate() method to protect it against access by more than
one thread.
Refers to global pointcut: class targetClassDeclaration
Triplet: unit add include
#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 targetClassUnit
Triplet: constructor begin codeFragment
mutex variable to the constructor.
The mutex variable has to be initialized prior its first use.
Refers to global pointcut: constructor targetConstructorImplementation
Triplet: function begin codeFragment
mutex. The code is inserted at the very
beginning of the target method.
Refers to global pointcut: function targetSynchronizedFunction
Triplet: function end codeFragment
mutex. The code is inserted at the very
end of the target method.
Refers to global pointcut: function targetSynchronizedFunction