CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
cmlabs::utils::Semaphore Class Reference

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

Detailed Description

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.

Definition at line 502 of file Utils.h.

Constructor & Destructor Documentation

◆ Semaphore() [1/2]

cmlabs::utils::Semaphore::Semaphore ( uint32 maxCount = 100)

Create an anonymous semaphore.

Parameters
maxCountMaximum count (Windows honours it strictly).

Definition at line 1270 of file Utils.cpp.

References name, and semaphore.

◆ Semaphore() [2/2]

cmlabs::utils::Semaphore::Semaphore ( const char * name,
uint32 maxCount = 100 )

Create or open a named, cross-process semaphore.

Parameters
nameGlobal name.
maxCountMaximum 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.

◆ ~Semaphore()

cmlabs::utils::Semaphore::~Semaphore ( )

Member Function Documentation

◆ signal()

bool cmlabs::utils::Semaphore::signal ( )

Increment (release) the semaphore, waking one waiter.

Returns
true on success.

Definition at line 1444 of file Utils.cpp.

References name, and semaphore.

Referenced by cmlabs::utils::SignalSemaphore().

◆ wait() [1/2]

bool cmlabs::utils::Semaphore::wait ( )

Block until the semaphore can be decremented.

Returns
true on success.

Definition at line 1375 of file Utils.cpp.

References name, and semaphore.

Referenced by cmlabs::utils::WaitForSemaphore().

◆ wait() [2/2]

bool cmlabs::utils::Semaphore::wait ( uint32 timeout)

Wait with a timeout.

Parameters
timeoutMax wait in milliseconds.
Returns
true when acquired, false on timeout.

Definition at line 1402 of file Utils.cpp.

References cmlabs::utils::CalcTimeout(), name, and semaphore.

Member Data Documentation

◆ name

char* cmlabs::utils::Semaphore::name

Definition at line 516 of file Utils.h.

Referenced by Semaphore(), Semaphore(), signal(), wait(), wait(), and ~Semaphore().

◆ semaphore

sem_t* cmlabs::utils::Semaphore::semaphore
protected

Definition at line 524 of file Utils.h.

Referenced by Semaphore(), Semaphore(), signal(), wait(), wait(), and ~Semaphore().


The documentation for this class was generated from the following files:
  • /home/ubuntu/c/partner/psyclone2/CMSDK/include/Utils.h
  • /home/ubuntu/c/partner/psyclone2/CMSDK/src/Utils.cpp