Gate‐keeper class for code that should only execute once per process.

Synopsis

Declared in <bslmt_once.h>

class Once;

Description

This class is a POD‐type and can be statically initialized to the value of the BSLMT_ONCE_INITIALIZE macro. For this reason, it does not have any explicitly‐declared constructors or destructor.

Type Aliases

Name

Description

OnceLock

Special token created by a single thread to pass to the enter, leave, and cancel methods.

Member Functions

Name

Description

callOnce

Call function at most once across all threads for this object.

cancel

Abort incomplete one‐time execution and unlock the internal mutex.

enter

Attempt to enter the one‐time execution region for this object.

isMaybeUninitialized

Return true if this object may not be in the "done" state (that is, leave has not been called).

leave

Mark one‐time execution as complete and unlock the internal mutex.

Data Members

Name

Description

d_mutex

Mutex used to synchronize one‐time execution. Public for static initialization, but do not access directly.

d_state

One‐time execution state. Public for static initialization, but do not access directly.

Created with MrDocs