CarSynchronizeWindows Aspect
[CarExample Synchronization Group]

This aspect is defined in file: ../../AspectXLib/car/Car/aspects/CarSyncWin.ax ../../AspectXLib/car/Car/aspects/CarSyncWin.ax

Aspect Description

Sample aspect program for "car example" that show how to add synchronization code (for MS Windows) to existing code. In this sample, the following is inserted:
  1. code to the constuctor that initializes a mutex (creates the constructor if it doesn't exist); mutex is a variable that has a mutual exclusive access and is used as a lock
  2. code that locks the mutex at the beginning of the synchronized function
  3. mutex variable to the class that is to be synchronized.
  4. preprocesor directives #include <windows.h> and #include "MutexWrapper.h"
It also uses the class MutexWrapper distributed together with other classes of car example. In order to test the aspect, check the main() function in the sample C++ code and uncommment three lines labled as to be commented out (lines 42 to 44 in main.cpp).
Author:
I. Birrer, O. Rohlik
See also:
CarBeginEnd
CarPostCondition
CarPreCondition
Synchronization

Pointcuts

classsyncClasses
  Points to all classes which have to be synchronized
unitsyncClassesDef
 Points to units (files) which contain the definitions of the methods to be synchronized
constructorsyncClassesConstrDef
 Points to definition of a constructor of the class that contains methods to be synchronized
constructor_declsyncClassesConstrDecl
 Points to declaration of a constructor of the class to be synchronized
functionlockedFunctions
 Points to all functions in the class to be synchronized

Advices

addaddConstrDecl
 Adds construtor declaration to classes which are to be sychronized and do not have a constructor
addaddConstrDef
 Adds construtor definition if the constructor was not defined
beginbeginLockFunction
 Locks the mutex at the beginning of each method in each class to be synchronized
addaddFields
 Adds field variable shared_mutex that is used as a lock to each class to be synchronized
addaddIncludesToDeclaration
 Adds appropriate header files to each file that contains classes to be synchronized
addaddIncludesToDefinition
 Adds appropriate header files to each definition file that contains definitions of methods of classes to be synchronized
begininitializeMutex
 Inserts a piece of code that initializes the lock

Pointcut Documentation

class syncClasses (source)
Points to all classes which have to be synchronized. In this sample aspect, only one class will be synchronized: PetrolStation.
unit syncClassesDef (source)
Points to units (files) which contain the definitions of the methods to be synchronized.
constructor syncClassesConstrDef (source)
Points to definition of a constructor of the class that contains methods to be synchronized.
constructor_decl syncClassesConstrDecl (source)
Points to declaration of a constructor of the class to be synchronized.
function lockedFunctions (source)
Points to all functions in the class to be synchronized.

Advice Documentation

add addConstrDecl (source)

Triplet: class add declaration

Adds construtor declaration to classes which are to be sychronized and do not have a constructor.

Local Pointcut: class (source)

add addConstrDef (source)

Triplet: unit add definition

Adds construtor definition if the constructor was not defined. It contains a piece of code that initializes the lock (mutex) variable.

Local Pointcut: unit (source)

begin beginLockFunction (source)

Triplet: function begin codeFragment

Locks the mutex at the beginning of each method in each class to be synchronized.

Refers to global pointcut: function lockedFunctions

add addFields (source)

Triplet: class add declaration

Adds field variable shared_mutex that is used as a lock to each class to be synchronized. The field variable is of type HANDLE.

Refers to global pointcut: class syncClasses

add addIncludesToDeclaration (source)

Triplet: unit add include

Adds appropriate header files to each file that contains classes to be synchronized. The inserted preprocesor directives are: #include <windows.h> and #include "MutexWrapper.h".

Local Pointcut: unit (source)

add addIncludesToDefinition (source)

Triplet: unit add include

Adds appropriate header files to each definition file that contains definitions of methods of classes to be synchronized. The inserted preprocesor directives are: #include <windows.h> and #include "MutexWrapper.h".

Refers to global pointcut: unit syncClassesDef

begin initializeMutex (source)

Triplet: constructor begin codeFragment

Inserts a piece of code that initializes the lock. It is inserted to the constuctor of class to be synchronized (if the constructor exists).

Refers to global pointcut: constructor syncClassesConstrDef