[#BloombergLP-bslmt-MeteredMutex]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::MeteredMutex
:relfileprefix: ../../
:mrdocs:

This class implements a mutex, that has the additional capability to keep track of hold time and wait time&period; The hold time is defined as the cumulative duration for which the mutex was in the locked state&period; The wait time is defined as the duration for which threads waited for the mutex&period;

== Synopsis

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

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

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslmt/MeteredMutex/2constructor.adoc[`MeteredMutex`]         [.small]#[constructor]#
| Create a metered mutex in the unlocked state&period;
| xref:BloombergLP/bslmt/MeteredMutex/2destructor.adoc[`&#126;MeteredMutex`] [.small]#[destructor]#
| Destroy this metered mutex&period;
| xref:BloombergLP/bslmt/MeteredMutex/holdTime.adoc[`holdTime`] 
| Return the hold time (in nanoseconds) accumulated since the most recent call to `resetMetrics` (or `MeteredMutex` if `resetMetrics` was never called)&period;
| xref:BloombergLP/bslmt/MeteredMutex/lastResetTime.adoc[`lastResetTime`] 
| Return the time in nanoseconds (referenced to an arbitrary but fixed origin) of the most recent invocation to `resetMetrics` (or creation time if `resetMetrics` was never invoked)&period; User can calculate the difference (in nanoseconds) between the current time and the last reset time by expression `bsls&colon;&colon;TimeUtil&colon;&colon;getTimer() &hyphen; clientMutex&period;lastResetTime()`&period;
| xref:BloombergLP/bslmt/MeteredMutex/lock.adoc[`lock`] 
| Acquire the lock on this metered mutex&period; If this mutex is currently locked, suspend the execution of the current thread until the lock can be acquired&period; Update the wait and hold time appropriately&period; The behavior is undefined if the calling thread already owns the lock&period;
| xref:BloombergLP/bslmt/MeteredMutex/resetMetrics.adoc[`resetMetrics`] 
| Reset the wait and hold time to zero and record the current time&period; All subsequent calls (that are made before a subsequent call to `resetMetrics`) to `waitTime` (or `holdTime`) will return the wait (or hold) time, accumulated since this call&period; Also, all subsequent calls (that are made before a subsequent call to `resetMetrics`) to `lastResetTime` will return the time of this call&period;
| xref:BloombergLP/bslmt/MeteredMutex/tryLock.adoc[`tryLock`] 
| Attempt to acquire the lock on this metered mutex&period; Return 0 on success, and a non&hyphen;zero value if this mutex is already locked, or if an error occurs&period; Update the wait and hold time appropriately&period; The behavior is undefined if the calling thread already owns the lock&period;
| xref:BloombergLP/bslmt/MeteredMutex/unlock.adoc[`unlock`] 
| Release the lock on this mutex that was previously acquired through a successful call to `lock` or `tryLock`&period; Update the hold time appropriately&period; The behavior is undefined unless the calling thread currently owns the lock&period;
| xref:BloombergLP/bslmt/MeteredMutex/waitTime.adoc[`waitTime`] 
| Return the wait time (in nanoseconds), accumulated since the most recent call to `resetMetrics` (or `MeteredMutex` if `resetMetrics` was never called)&period;
|===



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