NebulaStream  0.6.213
NebulaStream is a data and application management framework for the internet of things
NES::RequestProcessor::UnlockDeleter Class Reference

This class holds a lock on the supplied mutex on only releases it when it is destructed. It can be supplied as a custom deleter to a unique pointer to guarantee thread safe access to the resource held by the pointer without freeing the resource when the pointer is destructed. idea taken from: https://stackoverflow.com/questions/23610561/return-locked-resource-from-class-with-automatic-unlocking#comment36245473_23610561. More...

#include <UnlockDeleter.hpp>

Public Member Functions

 UnlockDeleter ()
 In case of serial access to the resource no mutex is needed and the destructor of the class will have no effect. More...
 
 UnlockDeleter (std::mutex &mutex)
 Blocks until a lock on the mutex is acquired, then keeps the lock until the object is destructed. More...
 
 UnlockDeleter (std::mutex &mutex, std::try_to_lock_t tryToLock)
 Tries to acquire a lock on the mutex. On success, the lock lives until the object is destroyed. Throws an exception if no lock could be acquired. More...
 
 UnlockDeleter (std::unique_lock< std::mutex > lock)
 Keeps the supplied lock in a locked state until the unlock deleter is destructed. Throws an exception if the supplied lock is not in locked state. More...
 
template<typename T >
void operator() (T *) const noexcept
 The action called when the unique pointer is destroyed. We use a no op be cause we do NOT want to free the resource. More...
 

Detailed Description

This class holds a lock on the supplied mutex on only releases it when it is destructed. It can be supplied as a custom deleter to a unique pointer to guarantee thread safe access to the resource held by the pointer without freeing the resource when the pointer is destructed. idea taken from: https://stackoverflow.com/questions/23610561/return-locked-resource-from-class-with-automatic-unlocking#comment36245473_23610561.

Constructor & Destructor Documentation

◆ UnlockDeleter() [1/4]

NES ::RequestProcessor::UnlockDeleter::UnlockDeleter ( )
explicitdefault

In case of serial access to the resource no mutex is needed and the destructor of the class will have no effect.

◆ UnlockDeleter() [2/4]

NES ::RequestProcessor::UnlockDeleter::UnlockDeleter ( std::mutex &  mutex)
explicit

Blocks until a lock on the mutex is acquired, then keeps the lock until the object is destructed.

Parameters
mutex

◆ UnlockDeleter() [3/4]

NES ::RequestProcessor::UnlockDeleter::UnlockDeleter ( std::mutex &  mutex,
std::try_to_lock_t  tryToLock 
)
explicit

Tries to acquire a lock on the mutex. On success, the lock lives until the object is destroyed. Throws an exception if no lock could be acquired.

Parameters
mutex
tryToLock

◆ UnlockDeleter() [4/4]

NES ::RequestProcessor::UnlockDeleter::UnlockDeleter ( std::unique_lock< std::mutex >  lock)
explicit

Keeps the supplied lock in a locked state until the unlock deleter is destructed. Throws an exception if the supplied lock is not in locked state.

Parameters
lockThe lock to be kept for the whole lifetime of the unlock deleter object

Member Function Documentation

◆ operator()()

template<typename T >
void NES::RequestProcessor::UnlockDeleter::operator() ( T *  ) const
inlinenoexcept

The action called when the unique pointer is destroyed. We use a no op be cause we do NOT want to free the resource.

Template Parameters
TThe type of the resource

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