TC::MT::LockerRef< T > Class Template Reference
[Multithreading]

Automatic locking class for references Class for automatic locking of a critical objects (like TC::MT::Mutex,TC::MT::ClassLevelLockable, TC::MT::ObjectLevelLockable. More...

#include <TCMTLock.h>

Inheritance diagram for TC::MT::LockerRef< T >:

Inheritance graph
[legend]
Collaboration diagram for TC::MT::LockerRef< T >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 LockerRef (T &critical)
 Constructs a Locker object.
 ~LockerRef ()
 Destructs the Locker object and unlocks the critical section associated with this object.

Private Attributes

T & m_critical
 Reference to the critical section used by this object.


Detailed Description

template<class T>
class TC::MT::LockerRef< T >

Automatic locking class for references Class for automatic locking of a critical objects (like TC::MT::Mutex,TC::MT::ClassLevelLockable, TC::MT::ObjectLevelLockable.

..). The class has to provide the methods Lock and UnLock

When constructing a Locker it automatically locks the critical object. This can be used when you have a methode which locks a critical object on enter and UnLocks it when leaving a method.

As an alternative to:

 void Test()
 {
    critical.Lock();
    .....
    .....
    .....
    critical.UnLock();
 }

you can use a single instance of the Locker class:

 void Test()
 {
    TCMT::Locker<type> lock(critical);
    ....
    ....
    ....
 }

This has the advantage that critical.UnLock() will be called automatically when an exception is thrown or the method is left.

Author:
Thomas Goessler

Definition at line 95 of file TCMTLock.h.


Constructor & Destructor Documentation

template<class T >
TC::MT::LockerRef< T >::LockerRef ( T &  critical  )  [inline]

Constructs a Locker object.

The critical object is automatically locked.

Parameters:
critical The reference of the object locked by this constructor.

Definition at line 104 of file TCMTLock.h.

References TC::MT::LockerRef< T >::m_critical.

template<class T >
TC::MT::LockerRef< T >::~LockerRef (  )  [inline]

Destructs the Locker object and unlocks the critical section associated with this object.

Definition at line 114 of file TCMTLock.h.

References TC::MT::LockerRef< T >::m_critical.


Member Data Documentation

template<class T >
T& TC::MT::LockerRef< T >::m_critical [private]

Reference to the critical section used by this object.

Definition at line 121 of file TCMTLock.h.

Referenced by TC::MT::LockerRef< T >::LockerRef(), and TC::MT::LockerRef< T >::~LockerRef().


The documentation for this class was generated from the following file:

Copyright (c) Thomas Goessler 2003 - 2008