Why: Semaphore#

class Semaphore#

Public Functions

Semaphore(unsigned int initial)#
void give()#

Increment the semaphore count (signal/post operation).

This operation is safe to call from interrupt service routines (ISRs).

void take()#

Decrement the semaphore count, blocking if necessary.

If the count is greater than zero, decrements it and returns immediately. Otherwise, blocks until another thread calls give().

bool take_noblock()#

Attempt to decrement the semaphore count without blocking.

This is the non-blocking version of take(). Safe to call from ISRs.

Returns:

true if the count was decremented, false if the count was zero.

inline int _pollfd() const#

Get the file descriptor for polling/event loop integration.

Returns:

int The underlying eventfd file descriptor.