00001 // -*- C++ -*- 00020 #ifndef COIL_GUARD_H 00021 #define COIL_GUARD_H 00022 00023 #include <coil/Mutex.h> 00024 00025 namespace coil 00026 { 00027 template <class M> 00028 class Guard 00029 { 00030 public: 00031 Guard(M& mutex) : m_mutex(mutex) 00032 { 00033 m_mutex.lock(); 00034 } 00035 ~Guard() 00036 { 00037 m_mutex.unlock(); 00038 } 00039 private: 00040 Guard(const Guard&); 00041 Guard& operator=(const Guard&); 00042 M& m_mutex; 00043 }; 00044 }; 00045 #endif // COIL_GUARD_H