Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

pmutex.h

Go to the documentation of this file.
00001 /*
00002  *   P::Classes - Portable C++ Application Framework
00003  *   Copyright (C) 2000-2003  Christian Prochnow <cproch@seculogix.de>
00004  *
00005  *   This library is free software; you can redistribute it and/or
00006  *   modify it under the terms of the GNU Lesser General Public
00007  *   License as published by the Free Software Foundation; either
00008  *   version 2 of the License, or (at your option) any later version.
00009  *   
00010  *   This library is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *   Lesser General Public License for more details.
00014  *   
00015  *   You should have received a copy of the GNU Lesser General Public
00016  *   License along with this library; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef _pmutex_h_
00021 #define _pmutex_h_
00022 
00023 #include <pclasses/pexport.h>
00024 #include <pclasses/pexception.h>
00025 
00026 namespace P {
00027 
00029 
00040 class PCORE_EXPORT Mutex {
00041   public:
00043 
00055     Mutex(const char* name = 0) throw(SyncError);
00056 
00058 
00064     ~Mutex() throw();
00065 
00067 
00079     void lock() throw(SyncError);
00080 
00082 
00091     bool tryLock(unsigned int timeout) throw(SyncError);
00092 
00094 
00100     void unlock() throw(SyncError);
00101 
00103 
00125     class Lock {
00126       public:
00127         inline Lock(Mutex& mutex)
00128         : m_mutex(mutex) { mutex.lock(); }
00129 
00130         ~Lock()
00131         { m_mutex.unlock(); }
00132 
00133         Lock& operator=(Mutex& mutex)
00134         {
00135           m_mutex.unlock();
00136           m_mutex = mutex;
00137           m_mutex.lock();
00138           return *this;
00139         }
00140 
00141       private:
00142         Lock(const Lock&);
00143         Lock& operator=(const Lock&);
00144         
00145         Mutex& m_mutex;
00146     };
00147     
00148   private:
00149     Mutex(const Mutex&);
00150     Mutex& operator=(const Mutex&);
00151  
00152     struct mutex_handle_t;
00153     mutex_handle_t* m_handle;
00154 };
00155 
00156 }
00157 
00158 #endif

Generated on Fri Mar 12 21:08:31 2004 for P::Classes by doxygen 1.3.3