14 #ifndef MULTIMUTEXESLOCK_HPP
15 #define MULTIMUTEXESLOCK_HPP
20 #include "codingUtilities/Utilities.hpp"
28 template<
typename ... Mutexes >
37 : m_islocked( false ), m_mutexes( mutexes ... )
55 if( m_islocked )
return;
56 apply( [](
auto && ... mutexes ){ std::lock( mutexes ... ); }, m_mutexes );
65 if( !m_islocked )
return;
66 forEachArgInTuple( m_mutexes, [](
auto & mutex,
auto ){ mutex.unlock(); } );
74 std::tuple< Mutexes &... > m_mutexes;
82 template<
typename ... Mutexes >
85 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,...