[#BloombergLP-bslmt-LockGuard-2constructor-0e8]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::xref:BloombergLP/bslmt/LockGuard.adoc[LockGuard]::LockGuard
:relfileprefix: ../../../
:mrdocs:

Create a guard that optionally locks `lock`&period;

== Synopsis

Declared in `&lt;bslmt&lowbar;lockguard&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
LockGuard(
    T* lock,
    bool alreadyLockedFlag);
----

== Description

Create a scoped guard that conditionally manages the specified `lock` (if non&hyphen;null) and invokes `lock&hyphen;&gt;lock()` if the specified `alreadyLockedFlag` is `false`&period; Supplying a null `lock` has no effect&period; The behavior is undefined unless the state of `lock` (if non&hyphen;null) is consistent with `alreadyLockedFlag`&period; Note that `alreadyLockedFlag` is used to indicate whether `lock` is in an already&hyphen;locked state when passed, so if `alreadyLockedFlag` is `true` the `lock` method will _not_ be called on the supplied `lock`&period; Also note that `lock` must remain valid throughout the lifetime of this guard, or until `release` is called&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *lock*
| lock object to acquire&semi; may be null
| *alreadyLockedFlag*
| `true` if `lock` is already locked
|===


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