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_SEM_H 00025 #define MN_OSS_SEM_H 00026 00027 #include "mnthread.h" 00028 #include "MNMutex.h" 00029 00030 /************************************************************* 00031 * class MNSem 00032 */ 00033 00034 class MNSem 00035 { 00036 public: 00037 MNSem ( ); 00038 ~MNSem ( ); 00039 00045 void signal ( ); 00046 00052 void broadcast ( ); 00053 00059 void wait ( MNMutex& m ); 00060 00074 int timedwait ( MNMutex& m, const struct timespec* abstime ); 00075 00076 protected: 00077 mnthread_condattr_t _attr; 00078 mnthread_cond_t _ctr; 00079 00080 inline bool do_attr_init( ) 00081 { 00082 return ( mnthread_condattr_init( &_attr ) == 0 ); 00083 } 00084 00085 inline bool do_init( ) 00086 { 00087 return ( mnthread_cond_init( &_ctr, &_attr ) == 0 ); 00088 } 00089 00090 inline bool do_destroy( ) 00091 { 00092 return ( mnthread_cond_destroy( &_ctr ) == 0 ); 00093 } 00094 00095 inline bool do_attr_destroy( ) 00096 { 00097 return ( mnthread_condattr_destroy( &_attr ) == 0 ); 00098 } 00099 00100 inline bool do_signal( ) 00101 { 00102 return ( mnthread_cond_signal ( &_ctr ) == 0 ); 00103 } 00104 00105 inline bool do_broadcast( ) 00106 { 00107 return ( mnthread_cond_broadcast ( &_ctr ) == 0 ); 00108 } 00109 00110 inline bool do_wait( MNMutex& m ) 00111 { 00112 return ( mnthread_cond_wait ( &_ctr, &m.lck ) == 0 ); 00113 } 00114 00115 inline bool do_timedwait( MNMutex& m, const struct timespec* to ) 00116 { 00117 return mnthread_cond_timedwait ( &_ctr, &m.lck, to ); 00118 } 00119 }; 00120 00121 /************************************************************* 00122 * class MNSemDebug 00123 */ 00124 00125 class MNSemDebug : public MNSem 00126 { 00127 DECLARE_VALID 00128 00129 private: 00130 char* _owner; 00131 00132 public: 00133 MNSemDebug( const char* owner ); 00134 ~MNSemDebug( ); 00135 00136 void signal ( ); 00137 void broadcast ( ); 00138 void wait ( MNMutex& m ); 00139 }; 00140 00141 #endif /* MN_OSS_SEM_H */ 00142