mutex.h

Go to the documentation of this file.
00001 //======================================================================
00002 // File:        mutex.h
00003 // Author:      Matthias Toussaint
00004 // Created:     Sat Nov 25 18:56:16 CET 2006
00005 // Project:     QtDMM
00006 // Description: Simplest possible posix mutex class
00007 //----------------------------------------------------------------------
00008 // This file  may  be used under  the terms of  the GNU  General Public
00009 // License  version 2.0 as published   by the Free Software  Foundation
00010 // and appearing  in the file LICENSE.GPL included  in the packaging of
00011 // this file.
00012 // 
00013 // This file is provided AS IS with  NO WARRANTY OF ANY KIND, INCLUDING 
00014 // THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00015 // PURPOSE.
00016 //----------------------------------------------------------------------
00017 // Copyright 2006 Matthias Toussaint
00018 //======================================================================
00019 
00020 #ifndef MUTEX_HH
00021 #define MUTEX_HH
00022 
00023 #include <pthread.h>
00024 
00029 class Mutex
00030 {
00031 public:
00032   Mutex();
00033   ~Mutex();
00034       
00039   int lock();
00044   int unlock();
00050   bool tryLock();
00055   bool isLocked();
00056   
00057 protected:
00058   pthread_mutex_t m_mutex;
00059   
00060 };
00061 
00070 class MutexLocker
00071 {
00072 public:
00073   MutexLocker( Mutex *mutex ) { m_mutex = mutex; m_mutex->lock(); }
00074   ~MutexLocker() { m_mutex->unlock(); }
00075       
00076 private:
00077   Mutex *m_mutex;
00078 
00079 };
00080     
00081 #endif // MUTEX_HH

Generated on Mon Jan 22 23:24:18 2007 for cdmm by  doxygen 1.4.6