27#include <boost/thread/condition_variable.hpp>
28#include <boost/thread/locks.hpp>
29#include <boost/thread/mutex.hpp>
30#include <boost/thread/recursive_mutex.hpp>
31#include <boost/thread/shared_mutex.hpp>
35#define MUTEX_TIMEOUT_MSEC 10000
48 std::stringstream reason;
49 reason <<
"A Thread failed to get a mutex '" + mutexName +
"' after "
50 << timeoutDelayMs * 0.001 <<
" seconds!";
51 setReason(reason.str());
57 return "armarx::exceptions::local::MutexTimeoutException";
64 LocalException(
"A mutex '" + mutexName +
65 "' was not already unlocked in the destructor!")
72 return "armarx::exceptions::local::MutexDestructionException";
90 boost::timed_mutex timedMutex;
92 std::string mutexName;
96 timeoutDelayMs(timeout), mutexName(mutexName)
105 std::cout <<
"A mutex ('" << mutexName
106 <<
"') was still locked in the destructor! Fix Application!\nBacktrace:\n"
107 << LocalException::generateBacktrace() << std::endl;
118 boost::system_time timeout =
119 boost::get_system_time() + boost::posix_time::milliseconds(timeoutDelayMs);
121 if (!timedMutex.timed_lock(timeout))
130 return timedMutex.try_lock();
#define MUTEX_TIMEOUT_MSEC
std::shared_ptr< ScopedLock > ScopedLockPtr
std::shared_ptr< ScopedTimedRecursiveLock > ScopedTimedRecursiveLockPtr
boost::condition_variable ConditionalVariable
boost::detail::try_lock_wrapper< HiddenTimedMutex > ScopedTryLock
boost::timed_mutex TimedMutex
RecursiveMutex::scoped_try_lock ScopedRecursiveTryLock
boost::shared_mutex SharedMutex
HiddenTimedMutex(int timeout=MUTEX_TIMEOUT_MSEC, std::string mutexName="")
Mutex::scoped_lock ScopedLock
TimedMutex::scoped_try_lock ScopedTimedTryMutex
boost::recursive_mutex RecursiveMutex
TimedRecursiveMutex::scoped_lock ScopedTimedRecursiveLock
std::shared_ptr< ScopedSharedLock > ScopedSharedLockPtr
Mutex::scoped_try_lock ScopedTryLock
boost::unique_lock< HiddenTimedMutex > ScopedLock
boost::unique_lock< boost::shared_mutex > ScopedUniqueLock
boost::shared_lock< boost::shared_mutex > ScopedSharedLock
std::shared_ptr< ScopedTimedMutex > ScopedTimedMutexPtr
TimedMutex::scoped_lock ScopedTimedMutex
TimedRecursiveMutex::scoped_try_lock ScopedTimedRecursiveTryLock
RecursiveMutex::scoped_lock ScopedRecursiveLock
boost::recursive_timed_mutex TimedRecursiveMutex
std::shared_ptr< ScopedUniqueLock > ScopedUniqueLockPtr
std::shared_ptr< ScopedRecursiveLock > ScopedRecursiveLockPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::string name() const override
MutexDestructionException(std::string mutexName="")
The MutexTimeoutException struct.
MutexTimeoutException(int timeoutDelayMs, std::string mutexName="")
std::string name() const override