#include <vpr/Sync/RWMutex.h>
Public Member Functions | |
| RWMutexPosix () | |
| Constructor for vpr::RWMutexPosix class. | |
| ~RWMutexPosix () | |
| Destructor for vpr::RWMutexPosix class. | |
| vpr::ReturnStatus | acquire () |
| Locks this mutex. | |
| vpr::ReturnStatus | acquireRead () |
| Acquires a read mutex. | |
| vpr::ReturnStatus | acquireWrite () |
| Acquire a write mutex. | |
| vpr::ReturnStatus | tryAcquire () |
| Tries to acquire a lock on this mutex variable (does not block). | |
| vpr::ReturnStatus | tryAcquireRead () |
| Tries to acquire a read mutex. | |
| vpr::ReturnStatus | tryAcquireWrite () |
| Tries to acquire a write mutex. | |
| vpr::ReturnStatus | release () |
| Releases the mutex. | |
| int | test () |
| Tests the current lock status. | |
Protected Member Functions | |
| void | operator= (const RWMutexPosix &) |
| RWMutexPosix (const RWMutexPosix &) | |
Protected Attributes | |
| pthread_rwlock_t | mRWMutex |
| RWMutex variable for the class. | |
| int | mLocked |
| If true, then we are locked. | |
This is typedef'd to vpr::RWMutex.
Definition at line 69 of file RWMutexPosix.h.
| vpr::RWMutexPosix::RWMutexPosix | ( | ) | [inline] |
Constructor for vpr::RWMutexPosix class.
Definition at line 79 of file RWMutexPosix.h.
References mRWMutex.
00079 : mLocked(0) 00080 { 00081 // Initialize the mutex. 00082 pthread_rwlock_init(&mRWMutex, NULL); 00083 }
| vpr::RWMutexPosix::~RWMutexPosix | ( | ) | [inline] |
Destructor for vpr::RWMutexPosix class.
Definition at line 93 of file RWMutexPosix.h.
References mRWMutex.
00094 { 00095 // Destroy the mutex. 00096 if ( pthread_rwlock_destroy(&mRWMutex) == -1 ) 00097 { 00098 pthread_rwlock_unlock(&mRWMutex); 00099 pthread_rwlock_destroy(&mRWMutex); 00100 } 00101 }
| vpr::RWMutexPosix::RWMutexPosix | ( | const RWMutexPosix & | ) | [inline, protected] |
| vpr::ReturnStatus vpr::RWMutexPosix::acquire | ( | ) | [inline] |
Locks this mutex.
vpr::ReturnStatus::Fail is returned if an error occurred.
Definition at line 115 of file RWMutexPosix.h.
References acquireWrite().
00116 { 00117 return acquireWrite(); 00118 }
| vpr::ReturnStatus vpr::RWMutex::acquireRead | ( | ) | [inline] |
Acquires a read mutex.
vpr::ReturnStatus::Fail is returned if an error occurred.
Definition at line 131 of file RWMutexPosix.h.
References vpr::ReturnStatus::Fail, mLocked, and mRWMutex.
Referenced by vpr::ReadGuard::acquire().
00132 { 00133 int retval = pthread_rwlock_rdlock(&mRWMutex); 00134 00135 // Locking succeeded. 00136 if ( retval == 0 ) 00137 { 00138 mLocked = 1; 00139 return vpr::ReturnStatus(); 00140 } 00141 #ifdef _DEBUG 00142 // This thread tried to lock the mutex twice and a deadlock condition 00143 // was reported. 00144 else if ( retval == EDEADLK ) 00145 { 00146 perror("Tried to lock mutex twice (RWMutexPosix.h:146)"); 00147 return vpr::ReturnStatus(vpr::ReturnStatus::Fail); 00148 } 00149 #endif 00150 // Some other error occurred. 00151 else 00152 { 00153 return vpr::ReturnStatus(vpr::ReturnStatus::Fail); 00154 } 00155 }
| vpr::ReturnStatus vpr::RWMutex::acquireWrite | ( | ) | [inline] |
Acquire a write mutex.
vpr::ReturnStatus::Fail is returned if an error occurred.
Definition at line 167 of file RWMutexPosix.h.
References vpr::ReturnStatus::Fail, mLocked, and mRWMutex.
Referenced by acquire(), and vpr::WriteGuard::acquire().
00168 { 00169 int retval = pthread_rwlock_wrlock(&mRWMutex); 00170 00171 // Locking succeeded. 00172 if ( retval == 0 ) 00173 { 00174 mLocked = 1; 00175 return vpr::ReturnStatus(); 00176 } 00177 #ifdef _DEBUG 00178 // This thread tried to lock the mutex twice and a deadlock condition 00179 // was reported. 00180 else if ( retval == EDEADLK ) 00181 { 00182 perror("Tried to lock mutex twice (RWMutexPosix.h:184)"); 00183 return vpr::ReturnStatus(vpr::ReturnStatus::Fail); 00184 } 00185 #endif 00186 // Some other error occurred. 00187 else 00188 { 00189 return vpr::ReturnStatus(vpr::ReturnStatus::Fail); 00190 } 00191 }
| vpr::ReturnStatus vpr::RWMutexPosix::tryAcquire | ( | ) | [inline] |
Tries to acquire a lock on this mutex variable (does not block).
vpr::ReturnStatus::Fail is returned if the mutex is already locked.
Definition at line 206 of file RWMutexPosix.h.
References tryAcquireWrite().
00207 { 00208 return tryAcquireWrite(); 00209 }
| vpr::ReturnStatus vpr::RWMutex::tryAcquireRead | ( | ) | [inline] |
Tries to acquire a read mutex.
vpr::ReturnStatus::Fail is returned if the mutex is already locked.
Definition at line 223 of file RWMutexPosix.h.
References vpr::ReturnStatus::Fail, mLocked, and mRWMutex.
Referenced by vpr::ReadGuard::tryAcquire().
00224 { 00225 if ( pthread_rwlock_tryrdlock(&mRWMutex) == 0 ) 00226 { 00227 mLocked = 1; 00228 return vpr::ReturnStatus(); 00229 } 00230 else 00231 { 00232 return vpr::ReturnStatus(vpr::ReturnStatus::Fail); 00233 } 00234 00235 }
| vpr::ReturnStatus vpr::RWMutex::tryAcquireWrite | ( | ) | [inline] |
Tries to acquire a write mutex.
vpr::ReturnStatus::Fail is returned if the mutex is already locked.
Definition at line 249 of file RWMutexPosix.h.
References vpr::ReturnStatus::Fail, mLocked, and mRWMutex.
Referenced by tryAcquire(), and vpr::WriteGuard::tryAcquire().
00250 { 00251 if ( pthread_rwlock_trywrlock(&mRWMutex) == 0 ) 00252 { 00253 mLocked = 1; 00254 return vpr::ReturnStatus(); 00255 } 00256 else 00257 { 00258 return vpr::ReturnStatus(vpr::ReturnStatus::Fail); 00259 } 00260 00261 }
| vpr::ReturnStatus vpr::RWMutex::release | ( | ) | [inline] |
Releases the mutex.
vpr::ReturnStatus::Fail is returned otherwise.
Definition at line 273 of file RWMutexPosix.h.
References vpr::ReturnStatus::Fail, mLocked, and mRWMutex.
Referenced by vpr::WriteGuard::release(), vpr::ReadGuard::release(), vpr::ReadGuard::~ReadGuard(), and vpr::WriteGuard::~WriteGuard().
00274 { 00275 mLocked = 0; 00276 if ( pthread_rwlock_unlock(&mRWMutex) == 0 ) 00277 { 00278 return vpr::ReturnStatus(); 00279 } 00280 else 00281 { 00282 return vpr::ReturnStatus(vpr::ReturnStatus::Fail); 00283 } 00284 }
| int vpr::RWMutexPosix::test | ( | ) | [inline] |
Tests the current lock status.
1 is returned if this mutex is locked.
Definition at line 294 of file RWMutexPosix.h.
References mLocked.
00295 { 00296 return mLocked; 00297 }
| void vpr::RWMutexPosix::operator= | ( | const RWMutexPosix & | ) | [inline, protected] |
pthread_rwlock_t vpr::RWMutexPosix::mRWMutex [protected] |
RWMutex variable for the class.
Definition at line 300 of file RWMutexPosix.h.
Referenced by acquireRead(), acquireWrite(), release(), RWMutexPosix(), tryAcquireRead(), tryAcquireWrite(), and ~RWMutexPosix().
int vpr::RWMutexPosix::mLocked [protected] |
If true, then we are locked.
Definition at line 301 of file RWMutexPosix.h.
Referenced by acquireRead(), acquireWrite(), release(), test(), tryAcquireRead(), and tryAcquireWrite().
1.5.1