#include <vpr/Sync/Semaphore.h>
Collaboration diagram for vpr::SemaphoreNSPR:

Public Member Functions | |
| SemaphoreNSPR (int initialValue=1) | |
| Custructor. | |
| ~SemaphoreNSPR () | |
| Destructor. | |
| vpr::ReturnStatus | acquire () |
| Locks this semaphore. | |
| vpr::ReturnStatus | acquireRead () |
| Acquires a read lock on a resource protected by this semaphore. | |
| vpr::ReturnStatus | acquireWrite () |
| Acquires a write lock on a resource protected by this semaphore. | |
| vpr::ReturnStatus | tryAcquire () |
| Tries to acquire the a resource lock immediately (does not block). | |
| vpr::ReturnStatus | tryAcquireRead () |
| Tries to acquire a read lock on a resource (does not block). | |
| vpr::ReturnStatus | tryAcquireWrite () |
| Tries to acquire a write lock on a resource (does not block). | |
| vpr::ReturnStatus | release () |
| Releases a resource lock. | |
| vpr::ReturnStatus | reset (int val) |
| Resets the resource count for this semaphore. | |
| void | dump (FILE *dest=stderr, const char *message="\n------ Semaphore Dump -----\n") const |
| Dumps the semaphore debug stuff and current state. | |
Protected Member Functions | |
| void | operator= (const SemaphoreNSPR &) |
| SemaphoreNSPR (const SemaphoreNSPR &) | |
Protected Attributes | |
| CondVar * | mCondVar |
| Semaphore simulator variable for the class. | |
| PRInt32 | mValue |
| The resource count. | |
This is typedef'd to vpr::Semaphore.
Definition at line 61 of file SemaphoreNSPR.h.
| vpr::SemaphoreNSPR::SemaphoreNSPR | ( | int | initialValue = 1 |
) | [inline] |
Custructor.
| initialValue | The initial number of resources controlled by the semaphore. If not specified, the default value is 1. |
Definition at line 73 of file SemaphoreNSPR.h.
| vpr::SemaphoreNSPR::~SemaphoreNSPR | ( | ) | [inline] |
Destructor.
Definition at line 84 of file SemaphoreNSPR.h.
00085 { 00086 delete mCondVar; 00087 }
| vpr::SemaphoreNSPR::SemaphoreNSPR | ( | const SemaphoreNSPR & | ) | [inline, protected] |
| vpr::ReturnStatus vpr::SemaphoreNSPR::acquire | ( | ) | [inline] |
Locks this semaphore.
Definition at line 100 of file SemaphoreNSPR.h.
00101 { 00102 mCondVar->acquire(); 00103 PR_AtomicDecrement(&mValue); 00104 00105 while ( mValue < 0 ) 00106 { 00107 mCondVar->wait(); 00108 } 00109 mCondVar->release(); 00110 00111 return vpr::ReturnStatus(); 00112 }
| vpr::ReturnStatus vpr::SemaphoreNSPR::acquireRead | ( | ) | [inline] |
Acquires a read lock on a resource protected by this semaphore.
Definition at line 127 of file SemaphoreNSPR.h.
00128 { 00129 return this->acquire(); 00130 }
| vpr::ReturnStatus vpr::SemaphoreNSPR::acquireWrite | ( | ) | [inline] |
Acquires a write lock on a resource protected by this semaphore.
Definition at line 145 of file SemaphoreNSPR.h.
00146 { 00147 return this->acquire(); 00148 }
| vpr::ReturnStatus vpr::SemaphoreNSPR::tryAcquire | ( | ) | [inline] |
Tries to acquire the a resource lock immediately (does not block).
Definition at line 162 of file SemaphoreNSPR.h.
References vpr::ReturnStatus::Fail.
00163 { 00164 vpr::ReturnStatus status(vpr::ReturnStatus::Fail); 00165 00166 if ( mValue >= 0 ) 00167 { 00168 status = this->acquire(); 00169 } 00170 00171 return status; 00172 }
| vpr::ReturnStatus vpr::SemaphoreNSPR::tryAcquireRead | ( | ) | [inline] |
Tries to acquire a read lock on a resource (does not block).
Definition at line 186 of file SemaphoreNSPR.h.
00187 { 00188 return this->tryAcquire(); 00189 }
| vpr::ReturnStatus vpr::SemaphoreNSPR::tryAcquireWrite | ( | ) | [inline] |
Tries to acquire a write lock on a resource (does not block).
Definition at line 203 of file SemaphoreNSPR.h.
00204 { 00205 return this->tryAcquire(); 00206 }
| vpr::ReturnStatus vpr::SemaphoreNSPR::release | ( | ) | [inline] |
Releases a resource lock.
Definition at line 219 of file SemaphoreNSPR.h.
00220 { 00221 vpr::ReturnStatus status; 00222 00223 mCondVar->acquire(); 00224 PR_AtomicIncrement(&mValue); 00225 status = mCondVar->signal(); 00226 mCondVar->release(); 00227 00228 return status; 00229 }
| vpr::ReturnStatus vpr::SemaphoreNSPR::reset | ( | int | val | ) | [inline] |
Resets the resource count for this semaphore.
| val | The value to which the semaphore is reset. |
Definition at line 245 of file SemaphoreNSPR.h.
00246 { 00247 vpr::ReturnStatus status; 00248 00249 mCondVar->acquire(); 00250 PR_AtomicSet(&mValue, val); 00251 status = mCondVar->broadcast(); 00252 mCondVar->release(); 00253 00254 return status; 00255 }
| void vpr::SemaphoreNSPR::dump | ( | FILE * | dest = stderr, |
|
| const char * | message = "\n------ Semaphore Dump -----\n" | |||
| ) | const [inline] |
Dumps the semaphore debug stuff and current state.
| dest | File descriptor to which the output will be written. It defaults to stderr if no descriptor is specified. | |
| message | Message printed out before the output is dumped. |
Definition at line 268 of file SemaphoreNSPR.h.
00270 { 00271 fprintf(dest, "%s", message); 00272 fprintf(dest, "Current semaphore value: %d", mValue); 00273 }
| void vpr::SemaphoreNSPR::operator= | ( | const SemaphoreNSPR & | ) | [inline, protected] |
CondVar* vpr::SemaphoreNSPR::mCondVar [protected] |
PRInt32 vpr::SemaphoreNSPR::mValue [protected] |
1.5.1