OMGuard class

OMGuard is used to make user operations guarded or locked between entry and exit. It is used in the generated code (in the GUARD_OPERATION macro) to ensure appropriate locking and freeing of the mutex in a guarded operation.

The copy constructor and assignment operator of OMGuard are explicitly disabled to avoid erroneous unlock of the guarded object mutex.

This class is defined in the header file omprotected.h.

Macro summary

END_REACTIVE_GUARDED_SECTION ends protection of a section of code used for a reactive object.

END_THREAD_GUARDED_SECTION stops protection for an operation of an active user object.

GUARD_OPERATION guards an operation by an OMGuard class object

START_DTOR_REACTIVE_GUARDED_SECTION starts protection of a section of code used for destruction of a reactive instance.

START_DTOR_THREAD_GUARDED_SECTION starts protection for an active user object destructor.

START_REACTIVE_GUARDED_SECTION starts protection of a section of code used for a reactive object.

START_THREAD_GUARDED_SECTION starts protection for an operation of an active user object.

Construction summary
OMGuard
Constructs an OMGuard object
~OMGuard
Destroys the OMGuard object
Method summary
getGuard
Gets the guard
lock
Locks the mutex of the OMGuard object
unlock
Unlocks the mutex of the OMGuard object

Macros

Macros

END_REACTIVE_GUARDED_SECTION

Ends protection of a section of code used for a reactive object. This macro is called in the reactive class event dispatching to prevent a "race" between the event dispatching and a deletion of the reactive class instance. The mechanism is activated when the reactive class DTOR is set to be guarded.

END_THREAD_GUARDED_SECTION

Stops protection for an operation of an active user object. The macro is used in OMThread event dispatching to guard the event dispatching from deletion of the active object. The mechanism is activated in the code generated for active classes, when the active class DTOR is set to be guarded.

The START_THREAD_GUARDED_SECTION macro and the END_THREAD_GUARDED_SECTION macros are called by the execute method if toGuardThread is TRUE.

GUARD_OPERATION

Guards an operation by an OMGuard class object. It is used in the generated code.

This macro supports the aggregation of OMProtected in guarded classes as well as inheritance from OMProtected by guarded classes.

OMDECLARE_GUARDED

Aggregates OMProtected objects inside guarded classes instead of inheritance from OMProtected. It is defined as follows:

#define OMDECLARE_GUARDED
  public:
     inline void lock() const {m_omGuard.lock();}
     inline void unlock() const
        {m_omGuard.unlock();}
     inline const OMProtected& getGuard() 
         const {return m_omGuard;}

START_DTOR_REACTIVE_GUARDED_SECTION

Starts protection of a section of code used for destruction of a reactive instance. This macro is called in the DTOR of a reactive (not active) class when it is set to guarded. This is done to prevent a "race" (between the deletion and the event dispatching) when deleting a reactive instance.

START_DTOR_THREAD_GUARDED_SECTION

Starts protection for an active user object destructor. This macro is called in the DTOR of an active class when it is set to guarded. This is done to prevent a "race" (between the deletion and the event dispatching) when deleting an active instance.

START_REACTIVE_GUARDED_SECTION

Starts protection of a section of code used for a reactive object. This macro is called in the reactive class event dispatching to prevent a "race" between the event dispatching and a deletion of the reactive class instance. The mechanism is activated when the reactive class DTOR is set to be guarded.

START_THREAD_GUARDED_SECTION

Starts protection for an operation of an active user object. The macro is used in OMThread event dispatching to guard the event dispatching from deletion of the active object. The mechanism is activated in the code generated for active classes when the active class DTOR is set to be guarded.

The START_THREAD_GUARDED_SECTION macro and the END_THREAD_GUARDED_SECTION macros are called by the execute method if toGuardThread is TRUE.


Feedback