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>
|
| 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...
|
|
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.
◆ 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
-
◆ 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
-
◆ 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
-
lock | The lock to be kept for the whole lifetime of the unlock deleter object |
◆ 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
-
T | The type of the resource |
The documentation for this class was generated from the following files:
- /nebulastream/nes-coordinator/include/RequestProcessor/StorageHandles/UnlockDeleter.hpp
- /nebulastream/nes-coordinator/src/RequestProcessor/StorageHandles/UnlockDeleter.cpp