[#BloombergLP-bsls-BslLockGuard] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bsls.adoc[bsls]::BslLockGuard :relfileprefix: ../../ :mrdocs: This `class` implements a guard for automatically acquiring and releasing the lock on an associated `bsls::BslLock` object. This mechanism follows the RAII idiom whereby the lock on the `BslLock` associated with a guard object is acquired upon construction and released upon destruction. == Synopsis Declared in `<bsls_bsllock.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class BslLockGuard; ---- == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bsls/BslLockGuard/2constructor.adoc[`BslLockGuard`] [.small]#[constructor]# | Create a guard object that conditionally manages the specified `lock`, and acquires the lock on `lock` by invoking its `lock` method. The behavior is undefined unless the calling thread does not already hold the lock on `lock`. Note that deadlock may result if a guard is created for `lock` while the calling thread holds the lock on `lock`. Also note that `lock` must remain valid throughout the lifetime of this guard, or until `release` is called. | xref:BloombergLP/bsls/BslLockGuard/2destructor.adoc[`~BslLockGuard`] [.small]#[destructor]# | Destroy this guard object and release the lock on the object it manages (if any) by invoking the `unlock` method of the object that was supplied at construction of this guard. If no lock is currently being managed, this method has no effect. Note that if this guard object currently manages a lock, this method assumes the behavior of `BslLock::unlock`. | xref:BloombergLP/bsls/BslLockGuard/release.adoc[`release`] | Release from management, with no effect, the object currently managed by this guard, if any. Note that `unlock` is _not_ called on the managed object upon its release. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#