gloox 1.0
|
00001 /* 00002 Copyright (c) 2007-2009 by Jakob Schroeter <js@camaya.net> 00003 This file is part of the gloox library. http://camaya.net/gloox 00004 00005 This software is distributed under a license. The full license 00006 agreement can be found in the file LICENSE in this distribution. 00007 This software may not be copied, modified, sold or distributed 00008 other than expressed in the named license agreement. 00009 00010 This software is distributed without any warranty. 00011 */ 00012 00013 00014 #ifndef MUTEXGUARD_H__ 00015 #define MUTEXGUARD_H__ 00016 00017 #include "mutex.h" 00018 00019 namespace gloox 00020 { 00021 00022 namespace util 00023 { 00024 00031 class GLOOX_API MutexGuard 00032 { 00033 public: 00038 MutexGuard( Mutex* mutex ) : m_mutex( *mutex ) { if( mutex ) m_mutex.lock(); } 00039 00044 MutexGuard( Mutex& mutex ) : m_mutex( mutex ) { m_mutex.lock(); } 00045 00049 ~MutexGuard() { m_mutex.unlock(); } 00050 00051 private: 00052 MutexGuard& operator=( const MutexGuard& ); 00053 Mutex& m_mutex; 00054 00055 }; 00056 00057 } 00058 00059 } 00060 00061 #endif // MUTEXGUARD_H__