rippled
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
ripple::scope_unlock< Mutex > Class Template Reference

Automatically unlocks and re-locks a unique_lock object. More...

#include <scope.h>

Collaboration diagram for ripple::scope_unlock< Mutex >:
Collaboration graph
[legend]

Public Member Functions

 scope_unlock (std::unique_lock< Mutex > &lock) noexcept(true)
 
 scope_unlock (scope_unlock const &)=delete
 
scope_unlockoperator= (scope_unlock const &)=delete
 
 ~scope_unlock () noexcept(true)
 

Private Attributes

std::unique_lock< Mutex > * plock
 

Detailed Description

template<class Mutex>
class ripple::scope_unlock< Mutex >

Automatically unlocks and re-locks a unique_lock object.

This is the reverse of a std::unique_lock object - instead of locking the mutex for the lifetime of this object, it unlocks it.

Make sure you don't try to unlock mutexes that aren't actually locked!

This is essentially a less-versatile boost::reverse_lock.

e.g.

for (;;)
{
std::unique_lock myScopedLock{mut};
// mut is now locked
... do some stuff with it locked ..
while (xyz)
{
... do some stuff with it locked ..
scope_unlock unlocker{myScopedLock};
// mut is now unlocked for the remainder of this block,
// and re-locked at the end.
...do some stuff with it unlocked ...
} // mut gets locked here.
} // mut gets unlocked here
Automatically unlocks and re-locks a unique_lock object.
Definition scope.h:231

Definition at line 230 of file scope.h.

Constructor & Destructor Documentation

◆ scope_unlock() [1/2]

template<class Mutex >
ripple::scope_unlock< Mutex >::scope_unlock ( std::unique_lock< Mutex > &  lock)
explicitnoexcept

Definition at line 235 of file scope.h.

◆ scope_unlock() [2/2]

template<class Mutex >
ripple::scope_unlock< Mutex >::scope_unlock ( scope_unlock< Mutex > const &  )
delete

◆ ~scope_unlock()

template<class Mutex >
ripple::scope_unlock< Mutex >::~scope_unlock ( )
noexcept

Definition at line 249 of file scope.h.

Member Function Documentation

◆ operator=()

template<class Mutex >
scope_unlock & ripple::scope_unlock< Mutex >::operator= ( scope_unlock< Mutex > const &  )
delete

Member Data Documentation

◆ plock

template<class Mutex >
std::unique_lock<Mutex>* ripple::scope_unlock< Mutex >::plock
private

Definition at line 232 of file scope.h.