Quick Links:

bal | bbl | bdl | bsl

Public Member Functions

bslmt::MeteredMutex Class Reference

#include <bslmt_meteredmutex.h>

List of all members.

Public Member Functions

 MeteredMutex ()
 ~MeteredMutex ()
void lock ()
void resetMetrics ()
int tryLock ()
void unlock ()
bsls::Types::Int64 holdTime () const
bsls::Types::Int64 lastResetTime () const
bsls::Types::Int64 waitTime () const

Detailed Description

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

See Component bslmt_meteredmutex


Constructor & Destructor Documentation

bslmt::MeteredMutex::MeteredMutex (  ) 

Create a metered mutex in the unlocked state.

bslmt::MeteredMutex::~MeteredMutex (  ) 

Destroy this metered mutex.


Member Function Documentation

void bslmt::MeteredMutex::lock (  ) 

Acquire the lock on this metered mutex. If this mutex is currently locked, suspend the execution of the current thread until the lock can be acquired. Update the wait and hold time appropriately. The behavior is undefined if the calling thread already owns the lock.

void bslmt::MeteredMutex::resetMetrics (  ) 

Reset the wait and hold time to zero and record the current time. 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. Also, all subsequent calls (that are made before a subsequent call to resetMetrics) to lastResetTime will return the time of this call.

int bslmt::MeteredMutex::tryLock (  ) 

Attempt to acquire the lock on this metered mutex. Return 0 on success, and a non-zero value if this mutex is already locked, or if an error occurs. Update the wait and hold time appropriately. The behavior is undefined if the calling thread already owns the lock.

void bslmt::MeteredMutex::unlock (  ) 

Release the lock on this mutex that was previously acquired through a successful call to lock or tryLock. Update the hold time appropriately. The behavior is undefined unless the calling thread currently owns the lock.

bsls::Types::Int64 bslmt::MeteredMutex::holdTime (  )  const

Return the hold time (in nanoseconds) accumulated since the most recent call to resetMetrics (or MeteredMutex if resetMetrics was never called).

bsls::Types::Int64 bslmt::MeteredMutex::lastResetTime (  )  const

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). User can calculate the difference (in nanoseconds) between the current time and the last reset time by expression bsls::TimeUtil::getTimer() - clientMutex.lastResetTime().

bsls::Types::Int64 bslmt::MeteredMutex::waitTime (  )  const

Return the wait time (in nanoseconds), accumulated since the most recent call to resetMetrics (or MeteredMutex if resetMetrics was never called).


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