00001 /* Copyright (C) 2000 KOM/Darmstadt University of Technology 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, code may be used in unmodified form provided 00006 * that this copyright notice and this permission notice appear in 00007 * supporting documentation. 00008 * 00009 * This software is provided "as is" and without any express or implied 00010 * warranties, including, without limitation, the implied warranty of 00011 * fitness for a particular purpose. 00012 * 00013 * The code may be subjected to the GNU General Public License, Version 2, 00014 * and re-distributed under the terms of this license. 00015 * As a special exception, permission is granted to link this code 00016 * with the Qt library and distribute executables, as long as you 00017 * follow the requirements of the GNU GPL in regard to all of the 00018 * software in the executable aside from Qt. 00019 * 00020 * Commercial use other than under the terms of the GNU General Public 00021 * License is allowed only after express negotiation of conditions 00022 * with the authors. 00023 */ 00024 #ifndef MN_OSS_MUTEX_H 00025 #define MN_OSS_MUTEX_H 00026 00027 #include <config.h> 00028 00029 #include "mnthread.h" 00030 #include "MNValid.h" 00031 00040 class MNDebugMutex 00041 { 00042 DECLARE_VALID 00043 00044 private: 00045 mnthread_t lock_holder; 00046 00047 protected: 00048 friend class MNSem; 00049 mnthread_mutex_t lck; 00050 00051 private: 00052 mnthread_mutexattr_t _attr; 00053 00054 public: 00060 MNDebugMutex( ); 00061 00066 ~MNDebugMutex( ); 00067 00071 void lock( ); 00072 00075 void unlock( ); 00076 }; 00077 00084 class MNMutex 00085 { 00086 DECLARE_VALID 00087 00088 protected: 00089 friend class MNSem; 00090 mnthread_mutex_t lck; 00091 00092 private: 00093 mnthread_mutexattr_t _attr; 00094 00095 public: 00101 MNMutex( ); 00102 00107 ~MNMutex( ); 00108 00111 void lock( ); 00112 00115 void unlock( ); 00116 }; 00117 00128 class Autolock 00129 { 00130 MNDebugMutex& _mx; 00131 public: 00132 Autolock( MNDebugMutex& mx ) 00133 : _mx( mx ) 00134 { 00135 _mx.lock(); 00136 } 00137 ~Autolock( ) 00138 { 00139 _mx.unlock(); 00140 } 00141 private: 00142 Autolock( const Autolock& ); 00143 Autolock& operator=( const Autolock& ); 00144 }; 00145 00146 #endif /* MN_OSS_MUTEX_H */ 00147