#include <Mutex.hpp>
Inheritance diagram for PThread_Mutex::
Public Methods | |
PThread_Mutex () | |
virtual | ~PThread_Mutex () |
void | lock () |
void | unlock () |
__inline void | tryLock () |
__inline int | getPriorityCeiling () |
__inline int | setPriorityCeiling (int new_ceiling) |
__inline int | getType () |
__inline int | getProtocol () |
Private Methods | |
__inline | PThread_Mutex (const PThread_Mutex &src) |
__inline const PThread_Mutex & | operator= (const PThread_Mutex &src) |
Private Attributes | |
int | mutex_type |
int | protocol |
int | prioceiling |
int | state |
pid_t | owner |
pthread_mutexattr_t | attr |
pthread_mutex_t | mutex |
|
Definition at line 12 of file Mutex.cpp. 00013 { 00014 // Fill structure with 0 00015 memset( &attr, 0, sizeof( pthread_mutexattr_t ) ); 00016 memset( &mutex, 0, sizeof( pthread_mutex_t ) ); 00017 00018 int err = pthread_mutexattr_init( &attr ); 00019 MC_OnError( err, Error, "An unknown error happened while initializing a mutex attribute." ) 00020 00021 err = pthread_mutex_init( &mutex, &attr ); 00022 MC_OnError( err, Error, "An error happened while initializing a mutex." ) 00023 00024 state = 0; 00025 } |
|
Definition at line 28 of file Mutex.cpp. 00029 { 00030 while( state > 0 ) { printf("DELETE" ); fflush( stdout ); exit( 1 ); } 00031 00032 int err = pthread_mutex_destroy( &mutex ); 00033 MC_OnError( err, Error, "An error happened while deleting a mutex." ) 00034 00035 00036 // Make sure the mutex is Unlock... 00037 00038 // WARNING: Make sure that Mutex destroy 00039 // ======== don't destroy attribute, 00040 // so that there is no double destroy on attr. 00041 00042 err = pthread_mutexattr_destroy( &attr ); 00043 MC_OnError( err, Error, "An error happened while deleting a mutex attribute." ) 00044 } |
|
|
|
Definition at line 34 of file Mutex.inl. 00035 { 00036 int ceiling = 0; 00037 int err = pthread_mutex_getprioceiling( &mutex, &ceiling ); 00038 MC_OnError( err, Error, "An error happened while retrieving the priority ceiling of a mutex." ) 00039 00040 return ceiling; 00041 } |
|
Definition at line 66 of file Mutex.inl. 00067 { 00068 int err = pthread_mutexattr_getprotocol( &attr, &protocol ); 00069 MC_OnError( err, Error, "while getting the mutex attribute protocol.") 00070 00071 return protocol; 00072 } |
|
Definition at line 55 of file Mutex.inl. 00056 { 00057 int mtype = 0; 00058 00059 int err = pthread_mutexattr_gettype( &attr, &mtype ); 00060 MC_OnError( err, Error, "An error happened while getting the mutex type." ) 00061 00062 return mtype; 00063 } |
|
Reimplemented in RecursiveMutex. Definition at line 47 of file Mutex.cpp. Referenced by Semaphore::P(), Semaphore::V(), Lock::get(), Semaphore::get(), RecursiveMutex::lock(), RWLock::read(), RWLock::releaseRead(), RWLock::releaseWrite(), Fred::run(), and RWLock::write().
00048 { 00049 // if ( state == 1 ) return; 00050 00051 if ( pthread_self() != owner ) { 00052 sched_yield(); 00053 } 00054 00055 state = 1; 00056 register int err = pthread_mutex_lock( &mutex ); 00057 MC_OnError( err, Error, "An error happened while locking a mutex." ) 00058 00059 owner = pthread_self(); 00060 } |
|
|
|
Definition at line 44 of file Mutex.inl. 00045 { 00046 int old_ceiling = 0; 00047 00048 int err = pthread_mutex_setprioceiling( &mutex, new_ceiling, &old_ceiling ); 00049 MC_OnError( err, Error, "An error happened while setting the priority ceiling of a mutex." ) 00050 00051 return old_ceiling; 00052 } |
|
Definition at line 27 of file Mutex.inl. 00028 { 00029 int err = pthread_mutex_trylock( &mutex ); 00030 MC_OnError( err, Error, "An error happened while trying to lock a mutex." ) 00031 } |
|
Reimplemented in RecursiveMutex. Definition at line 63 of file Mutex.cpp. Referenced by Semaphore::P(), Semaphore::V(), Semaphore::get(), if(), RWLock::read(), Lock::release(), RWLock::releaseRead(), RWLock::releaseWrite(), Fred::run(), and RWLock::write().
00064 { 00065 // if ( state == 0 ) return; 00066 00067 if ( pthread_self() != owner ) { 00068 sched_yield(); 00069 return; 00070 } 00071 register int err = pthread_mutex_unlock( &mutex ); 00072 00073 if ( err == EPERM ) { 00074 printf( "Unlock. Permission denied. Not owner." ); 00075 } else { 00076 MC_OnError( err, Error, "An error happened while unlocking a mutex." ) 00077 } 00078 state = 0; 00079 } |
|
Definition at line 64 of file Mutex.hpp. Referenced by PThread_Mutex(), and operator=().
|
|
Definition at line 65 of file Mutex.hpp. Referenced by PThread_Mutex(), and operator=().
|
|
|
|
Reimplemented in RecursiveMutex. |
|
|
|
|
|
|