00001
00002
00003
00004 #ifndef __J2K__PThread_Mutex_CPP__
00005 #define __J2K__PThread_Mutex_CPP__
00006
00007 #include <j2k/445/Posix/Mutex.hpp>
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 inline PThread_Mutex::PThread_Mutex()
00030 {
00031
00032 memset( &attr, 0, sizeof( pthread_mutexattr_t ) );
00033 memset( &mutex, 0, sizeof( pthread_mutex_t ) );
00034
00035
00036
00037 int err = pthread_mutexattr_init( &attr );
00038 MC_OnError( err, Error, "An unknown error happened while initializing a mutex attribute." )
00039
00040 err = pthread_mutex_init( &mutex, &attr );
00041 MC_OnError( err, Error, "An error happened while initializing a mutex." )
00042
00043
00044
00045
00046
00047
00048 }
00049
00050
00051 inline PThread_Mutex::PThread_Mutex( const PThread_Mutex& src ) {
00052 memcpy( &attr, &src.attr, sizeof( pthread_mutexattr_t ) );
00053 memcpy( &mutex, &src.mutex, sizeof( pthread_mutex_t ) );
00054
00055
00056 }
00057
00058
00059 inline const PThread_Mutex& PThread_Mutex::operator=( const PThread_Mutex& src )
00060 {
00061 memcpy( &attr, &src.attr, sizeof( pthread_mutexattr_t ) );
00062 memcpy( &mutex, &src.mutex, sizeof( pthread_mutex_t ) );
00063
00064
00065 return *this;
00066 }
00067
00068
00069 inline PThread_Mutex::~PThread_Mutex()
00070 {
00071 int err = pthread_mutex_destroy( &mutex );
00072 MC_OnError( err, Error, "An error happened while deleting a mutex." )
00073
00074
00075
00076
00077
00078
00079
00080
00081 err = pthread_mutexattr_destroy( &attr );
00082 MC_OnError( err, Error, "An error happened while deleting a mutex attribute." )
00083
00084
00085
00086
00087
00088
00089 }
00090
00091
00092 inline void PThread_Mutex::lock()
00093 {
00094 int err = pthread_mutex_lock( &mutex );
00095 MC_OnError( err, Error, "An error happened while locking a mutex." )
00096 }
00097
00098
00099 inline void PThread_Mutex::unlock()
00100 {
00101 int err = pthread_mutex_unlock( &mutex );
00102 MC_OnError( err, Error, "An error happened while unlocking a mutex." )
00103 }
00104
00105
00106 inline void PThread_Mutex::tryLock()
00107 {
00108 int err = pthread_mutex_trylock( &mutex );
00109 MC_OnError( err, Error, "An error happened while trying to lock a mutex." )
00110 }
00111
00112
00113 inline int PThread_Mutex::getPriorityCeiling()
00114 {
00115 int ceiling = 0;
00116 int err = pthread_mutex_getprioceiling( &mutex, &ceiling );
00117 MC_OnError( err, Error, "An error happened while retrieving the priority ceiling of a mutex." )
00118
00119 return ceiling;
00120 }
00121
00122
00123 inline int PThread_Mutex::setPriorityCeiling( int new_ceiling )
00124 {
00125 int old_ceiling = 0;
00126
00127 int err = pthread_mutex_setprioceiling( &mutex, new_ceiling, &old_ceiling );
00128 MC_OnError( err, Error, "An error happened while setting the priority ceiling of a mutex." )
00129
00130 return old_ceiling;
00131 }
00132
00133
00134 inline int PThread_Mutex::getType()
00135 {
00136 int mtype = 0;
00137
00138 int err = pthread_mutexattr_gettype( &attr, &mtype );
00139 MC_OnError( err, Error, "An error happened while getting the mutex type." )
00140
00141 return mtype;
00142 }
00143
00144
00145 inline int PThread_Mutex::getProtocol()
00146 {
00147 int err = pthread_mutexattr_getprotocol( &attr, &protocol );
00148 MC_OnError( err, Error, "while getting the mutex attribute protocol.")
00149
00150 return protocol;
00151 }
00152
00153 #if 0
00154
00155 inline void PThread_Mutex::wait()
00156 {
00157
00158 }
00159
00160
00161 inline void PThread_Mutex::notify()
00162 {
00163 pthread_cond_signal( &cond );
00164 }
00165
00166
00167 inline void PThread_Mutex::notifyAll()
00168 {
00169
00170 }
00171 #endif
00172
00173 #endif
00174