Argon RTOS
1.3.0
Tiny embedded real-time kernel
|
#include <ar_classes.h>
Counting semaphore class.
Public Member Functions | |
Semaphore () | |
Default constructor. | |
Semaphore (const char *name, unsigned count=1) | |
Constructor. | |
~Semaphore () | |
Destructor. More... | |
ar_status_t | get (uint32_t timeout=kArInfiniteTimeout) |
Acquire the semaphore. More... | |
unsigned | getCount () const |
Returns the current semaphore count. | |
const char * | getName () const |
Get the semaphore's name. | |
ar_status_t | init (const char *name, unsigned count=1) |
Initialiser. More... | |
ar_status_t | put () |
Release the semaphore. More... | |
|
inline |
Destructor.
Any threads on the blocked list will be unblocked immediately. Their return status from the get() method will be kArObjectDeletedError.
|
inline |
Acquire the semaphore.
The semaphore count is decremented. If the count is 0 upon entering this method then the caller thread is blocked until the count reaches 1. Threads are unblocked in the order in which they were blocked. Priority is not taken into consideration, so priority inversions are possible.
timeout | The maximum number of milliseconds that the caller is willing to wait in a blocked state before the semaphore can be obtained. If this value is 0, or kArNoTimeout, then this method will return immediately if the semaphore cannot be obtained. Setting the timeout to kArInfiniteTimeout will cause the thread to wait forever for a chance to get the semaphore. |
kArSuccess | The semaphore was obtained without error. |
kArTimeoutError | The specified amount of time has elapsed before the semaphore could be obtained. |
kArObjectDeletedError | Another thread deleted the semaphore while the caller was blocked on it. |
kArNotFromInterruptError | A non-zero timeout is not alllowed from the interrupt context. |
|
inline |
Initialiser.
name | Pass a name for the semaphore. If NULL is passed the name will be set to an empty string. |
count | The initial semaphore count. Setting this value to 0 will cause the first call to get() to block until put() is called. A value of 1 or greater will allow that many calls to get() to succeed. |
kArSuccess | Semaphore initialised successfully. |
|
inline |
Release the semaphore.
The semaphore count is incremented.
kArSuccess | The semaphore was released without error. |