Fiber‐compatible semaphore. Will safely block fibers that wait when no tokens are available and wake fibers when signalled.

Synopsis

Declared in <folly/fibers/Semaphore.h>

class Semaphore;

Description

Fair. Waiters are awoken in FIFO order. (Note: whether the callers see FIFO order depends on the executors, wrapping async types, and the existence of happens‐before relationships between async wait operations.)

Types

Name

Description

Waiter

A queued waiter that is notified when the semaphore acquires capacity.

Member Functions

Name

Description

Semaphore [constructor]

Constructors

operator=

Assignment operators

co_try_wait_for

Wait for capacity in the semaphore with a timeout.

co_wait

Wait for capacity in the semaphore.

future_wait

Wait for capacity in the semaphore.

getAvailableTokens

Return the number of tokens currently available.

getCapacity

Return the total number of tokens the semaphore was created with.

signal

Release a token in the semaphore. Signal the waiter if necessary.

try_wait

try_wait overloads

wait

Wait for capacity in the semaphore.

Created with MrDocs