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

Synopsis

Declared in <folly/fibers/SemaphoreBase.h>

class SemaphoreBase;

Types

Name

Description

Waiter

A queued waiter blocked until the semaphore has capacity.

Member Functions

Name

Description

SemaphoreBase [constructor]

Constructors

operator=

Assignment operators

getAvailableTokens

Returns the number of tokens currently available.

getCapacity

Returns the total number of tokens the semaphore can hold.

Protected Type Aliases

Name

Description

WaiterList

List of waiters queued for capacity.

Protected Member Functions

Name

Description

co_wait_common

Wait for request capacity in the semaphore.

future_wait_common

Wait for request capacity in the semaphore, returning a future.

signalSlow

Slow path that wakes queued waiters when tokens become available.

try_wait_common

try_wait_common overloads

waitSlow

Slow path that enqueues the waiter when tokens are unavailable.

wait_common

Wait for request capacity in the semaphore.

Protected Data Members

Name

Description

capacity_

Total number of tokens the semaphore can hold.

tokens_

Atomic counter of currently available tokens.

waitList_

Synchronized queue of pending waiters.

Derived Classes

Name

Description

BatchSemaphore

Fiber‐compatible batch semaphore with ability to perform batch token increment/decrement. Will safely block fibers that wait when no tokens are available and wake fibers when signalled.

Created with MrDocs