xrpld
Loading...
Searching...
No Matches
xrpl::ScopeUnlock< Mutex > Class Template Reference

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

#include <scope.h>

Collaboration diagram for xrpl::ScopeUnlock< Mutex >:

Public Member Functions

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

Private Attributes

std::unique_lock< Mutex > * plock_

Detailed Description

template<class Mutex>
class xrpl::ScopeUnlock< 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

Definition at line 201 of file scope.h.

Constructor & Destructor Documentation

◆ ScopeUnlock() [1/2]

template<class Mutex>
xrpl::ScopeUnlock< Mutex >::ScopeUnlock ( std::unique_lock< Mutex > & lock)
explicitnoexcept

Definition at line 206 of file scope.h.

◆ ScopeUnlock() [2/2]

template<class Mutex>
xrpl::ScopeUnlock< Mutex >::ScopeUnlock ( ScopeUnlock< Mutex > const & )
delete

◆ ~ScopeUnlock()

template<class Mutex>
xrpl::ScopeUnlock< Mutex >::~ScopeUnlock ( )
noexcept

Definition at line 217 of file scope.h.

Member Function Documentation

◆ operator=()

template<class Mutex>
ScopeUnlock & xrpl::ScopeUnlock< Mutex >::operator= ( ScopeUnlock< Mutex > const & )
delete

Member Data Documentation

◆ plock_

template<class Mutex>
std::unique_lock<Mutex>* xrpl::ScopeUnlock< Mutex >::plock_
private

Definition at line 203 of file scope.h.