Quick Links:

bal | bbl | bdl | bsl

Public Member Functions

bslmt::OnceGuard Class Reference

#include <bslmt_once.h>

List of all members.

Public Member Functions

 OnceGuard (Once *once=0)
 ~OnceGuard ()
void setOnce (Once *once)
bool enter ()
void leave ()
void cancel ()
bool isInProgress () const

Detailed Description

Guard class for using Once safely. Construct an object of this class before conditionally entering one-time processing code. Destroy the object when the one-time code is complete. When used this way, this object will be in an "in-progress" state during the time that the one-time code is being executed.

See Component bslmt_once


Constructor & Destructor Documentation

bslmt::OnceGuard::OnceGuard ( Once once = 0  )  [explicit]

Initialize this object to guard the (optionally) specified once object. If once is not specified, then it must be set later using the setOnce method before other methods may be called.

bslmt::OnceGuard::~OnceGuard (  ) 

Destroy this object. If this object is not in an "in-progress" state, do nothing. If this object is in an "in-progress" state and is being destroyed in the course of normal processing, then call leave on the associated Once object. Due to a bug in the MS VC++ 2003 compiler, the behavior is undefined if this destructor is called in the course of stack-unwinding during exception processing (i.e., if an exception escapes from the one-time code region. [Eventually, we hope to call cancel if this destructor is called during exception-processing.]


Member Function Documentation

void bslmt::OnceGuard::setOnce ( Once once  ) 

Set this object to guard the specified once object. The behavior is undefined if this object is currently in the "in-progress" state.

bool bslmt::OnceGuard::enter (  ) 

Call enter on the associated Once object and return the result. If Once::enter returns true, set this object into the "in-progress" state. The behavior is undefined unless this object has been associated with a Once object, either in the constructor or using setOnce, or if this object is already in the "in-progress" state.

void bslmt::OnceGuard::leave (  ) 

If this object is in the "in-progress" state, call leave on the associated Once object and exit the "in-progress" state. Otherwise, do nothing.

void bslmt::OnceGuard::cancel (  ) 

If this object is in the "in-progress" state, call cancel on the associated Once object and exit the "in-progress" state. Otherwise, do nothing.

bool bslmt::OnceGuard::isInProgress (  )  const

Return true if this object is in the "in-progress" state. The object is in-progress if enter has been called and returned true and neither leave nor cancel have been called. The one-time code controlled by this object should only be executing if this object is in the "in-progress" state.


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