|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Counting semaphore, optionally named for cross-process use. More...
#include <Utils.h>
Public Member Functions | |
| Semaphore (uint32 maxCount=100) | |
| Create an anonymous semaphore. | |
| Semaphore (const char *name, uint32 maxCount=100) | |
| Create or open a named, cross-process semaphore. | |
| ~Semaphore () | |
| bool | wait () |
| Block until the semaphore can be decremented. | |
| bool | wait (uint32 timeout) |
| Wait with a timeout. | |
| bool | signal () |
| Increment (release) the semaphore, waking one waiter. | |
Public Attributes | |
| char * | name |
Protected Attributes | |
| sem_t * | semaphore |
Counting semaphore, optionally named for cross-process use.
On macOS an unnamed semaphore uses libdispatch (dispatch_semaphore_t) while named ones are emulated in shared memory, because POSIX unnamed semaphores are unsupported there — hence the void* semaphore_impl member.
| cmlabs::utils::Semaphore::Semaphore | ( | uint32 | maxCount = 100 | ) |
| cmlabs::utils::Semaphore::Semaphore | ( | const char * | name, |
| uint32 | maxCount = 100 ) |
Create or open a named, cross-process semaphore.
| name | Global name. |
| maxCount | Maximum count. |
Definition at line 1291 of file Utils.cpp.
References cmlabs::utils::CreateSharedMemorySegment(), MAXKEYNAMELEN, MAXSHMEMNAMELEN, name, cmlabs::utils::OpenSharedMemorySegment(), semaphore, SEMAPHOREMEMSIZE, cmlabs::utils::strcpyavail(), and WINSHMEMSPACE.
| cmlabs::utils::Semaphore::~Semaphore | ( | ) |
Definition at line 1340 of file Utils.cpp.
References cmlabs::utils::CloseSharedMemorySegment(), name, semaphore, and SEMAPHOREMEMSIZE.
| bool cmlabs::utils::Semaphore::signal | ( | ) |
Increment (release) the semaphore, waking one waiter.
Definition at line 1444 of file Utils.cpp.
References name, and semaphore.
Referenced by cmlabs::utils::SignalSemaphore().
| bool cmlabs::utils::Semaphore::wait | ( | ) |
Block until the semaphore can be decremented.
Definition at line 1375 of file Utils.cpp.
References name, and semaphore.
Referenced by cmlabs::utils::WaitForSemaphore().
| bool cmlabs::utils::Semaphore::wait | ( | uint32 | timeout | ) |
Wait with a timeout.
| timeout | Max wait in milliseconds. |
Definition at line 1402 of file Utils.cpp.
References cmlabs::utils::CalcTimeout(), name, and semaphore.
| char* cmlabs::utils::Semaphore::name |
Definition at line 516 of file Utils.h.
Referenced by Semaphore(), Semaphore(), signal(), wait(), wait(), and ~Semaphore().
|
protected |
Definition at line 524 of file Utils.h.
Referenced by Semaphore(), Semaphore(), signal(), wait(), wait(), and ~Semaphore().