[#BloombergLP-bsls-BslOnceGuard]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bsls.adoc[bsls]::BslOnceGuard
:relfileprefix: ../../
:mrdocs:

This class provides a guard for managing a `BslOnce` for the purpose of executing a block of code (only) once&period;

== Synopsis

Declared in `&lt;bsls&lowbar;bslonce&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class BslOnceGuard;
----

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bsls/BslOnceGuard/2constructor.adoc[`BslOnceGuard`]         [.small]#[constructor]#
| Create a guard to manage a block of code that is executed once&period;
| xref:BloombergLP/bsls/BslOnceGuard/2destructor.adoc[`&#126;BslOnceGuard`] [.small]#[destructor]#
| 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&hyphen;time block of code&period;
| xref:BloombergLP/bsls/BslOnceGuard/enter.adoc[`enter`] 
| Enter the one&hyphen;time block of code that is managed by the specified `once`&period; Return `true` if the one&hyphen;time block of code has been entered, and `false` if the one&hyphen;time block of code has already been executed&period; If this function returns `false` then the thread of execution in which `enter` returned `true` has already called `leave` &hyphen;&hyphen; i&period;e&period;, the one&hyphen;time block of code is guaranteed to have _completed_ execution&period; The behavior is undefined unless `once` was originally initialized to `BSLS&lowbar;BSLONCE&lowbar;INITIALIZER`&period; Note that a successful `enter` locks a spin&hyphen;lock&semi; it is imperative that `leave` be called quickly&period;
| xref:BloombergLP/bsls/BslOnceGuard/leave.adoc[`leave`] 
| Exit the one&hyphen;time block of code&period; The behavior is undefined unless the caller had previously called `enter`, and `enter` had returned `true`&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
