SourceForge.net Logo
Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

EkGuard Class Template Reference

EkGuard - lock management. More...

#include <EkGuard.h>

Collaboration diagram for EkGuard:

[legend]
List of all members.

Public Methods

 EkGuard (T &lock)
 ~EkGuard ()

Detailed Description

template<class T>
class EkGuard< T >

EkGuard - lock management.

An EkGuard object provides an easy and safe way to use a mutex or other lock object. The lock object must implement two methods: lock() and unlock().

When an EkGuard is constructed it locks the lock. When it is destroyed, it unlocks the lock.

An EkGuard that is declared as a local (neither extern, static, nor on the heap) will always be destroyed at the end of the block in which it was declared, thus unlocking the lock. This can help to avoid leaving the lock inadvertently locked, such as when an exception causes an immediate exit from the block.

Example:

      Mutex useCountMutex;    // protects useCount
      long useCount;


      void bumpUseCount()
      { 
          EkGuard<Mutex> guard(useCountMutex);
          theUseCount++;
      }
 


Constructor & Destructor Documentation

template<class T>
EkGuard< T >::EkGuard T &    lock [inline]
 

template<class T>
EkGuard< T >::~EkGuard   [inline]
 


The documentation for this class was generated from the following file:
Last Updated: March 12, 2003 (rlr)
Copyright © 2003 Eastman Kodak Company All Rights Reserved.