BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bsls::BslOnceGuard Class Reference

#include <bsls_bslonce.h>

Detailed Description

This class provides a guard for managing a BslOnce for the purpose of executing a block of code (only) once.

See bsls_bslonce

Public Member Functions

 BslOnceGuard ()
 
 ~BslOnceGuard ()
 
bool enter (BslOnce *once)
 
void leave ()
 

Constructor & Destructor Documentation

◆ BslOnceGuard()

bsls::BslOnceGuard::BslOnceGuard ( )
inline

Create a guard to manage a block of code that is executed once.

◆ ~BslOnceGuard()

bsls::BslOnceGuard::~BslOnceGuard ( )
inline

Destroy this guard, and if enter had been called on this object without a subsequent call to leave, then call leave to signal the completion of the one-time block of code.

Member Function Documentation

◆ enter()

bool bsls::BslOnceGuard::enter ( BslOnce once)
inline

Enter the one-time block of code that is managed by the specified once. Return true if the one-time block of code has been entered, and false if the one-time block of code has already been executed. If this function returns false then the thread of execution in which enter returned true has already called leave – i.e., the one-time block of code is guaranteed to have completed execution.

Precondition
The behavior is undefined unless once was originally initialized to BSLS_BSLONCE_INITIALIZER.
Note
Note that a successful enter locks a spin-lock; it is imperative that leave be called quickly.

◆ leave()

void bsls::BslOnceGuard::leave ( )
inline

Exit the one-time block of code.

Precondition
The behavior is undefined unless the caller had previously called enter, and enter had returned true.

The documentation for this class was generated from the following file: