cvd/synchronized.h

00001 #ifndef SYNCHRONIZED_H_
00002 #define SYNCHRONIZED_H_
00003 
00004 // POSIX threads
00005 #include <pthread.h>
00006 
00007 namespace CVD {
00008 
00014 class Synchronized
00015 {
00016  public:
00018   Synchronized();
00020   virtual ~Synchronized();
00022 
00025   void lock() const;
00026    
00028   void unlock() const;
00029    
00030  protected:
00031    static pthread_mutexattr_t ourAttr;
00032    static bool ourInitFlag;
00033    mutable pthread_mutex_t myMutex; 
00034 };
00035 
00040 struct Lock {
00041   const Synchronized& myObject;
00042   Lock(const Synchronized& obj) : myObject(obj) { myObject.lock(); }
00043   virtual ~Lock() { myObject.unlock(); }
00044 };
00045 
00046 }  
00047 #endif

Generated on Wed Feb 18 10:23:02 2009 for CVD by  doxygen 1.5.3