16 #ifndef MULTIMUTEXESLOCK_HPP
17 #define MULTIMUTEXESLOCK_HPP
22 #include "codingUtilities/Utilities.hpp"
30 template<
typename ... Mutexes >
39 : m_islocked( false ), m_mutexes( mutexes ... )
57 if( m_islocked )
return;
58 apply( [](
auto && ... mutexes ){ std::lock( mutexes ... ); }, m_mutexes );
67 if( !m_islocked )
return;
68 forEachArgInTuple( m_mutexes, [](
auto & mutex,
auto ){ mutex.unlock(); } );
76 std::tuple< Mutexes &... > m_mutexes;
84 template<
typename ... Mutexes >
87 return MultiMutexesLock< Mutexes... >( std::forward< Mutexes >( mutexes )... );
Class to handle locks using 2 mutexes.
~MultiMutexesLock()
Unlock the mutexes and destroy the locks.
void lock()
Lock the two mutexes using std::lock is not already owning lock.
MultiMutexesLock(Mutexes &... mutexes)
Construct a multi mutexes lock and lock the mutexes.
void unlock()
Unlock the two mutexes is owning them.
auto make_multilock(Mutexes &&... mutexes)
Helper to construct MultiMutexesLock (usage auto lock = make_multilock( mutex1, mutex2,...