29 #include <boost/thread/locks.hpp>
31 #include <boost/thread/mutex.hpp>
32 #include <boost/thread/recursive_mutex.hpp>
33 #include <boost/thread/shared_mutex.hpp>
34 #include <boost/thread/condition_variable.hpp>
36 #define MUTEX_TIMEOUT_MSEC 10000
48 std::stringstream reason;
49 reason <<
"A Thread failed to get a mutex '" + mutexName +
"' after " <<
50 timeoutDelayMs * 0.001 <<
52 setReason(reason.str());
54 std::string
name()
const override
56 return "armarx::exceptions::local::MutexTimeoutException";
62 MutexDestructionException(std::string mutexName =
"") : LocalException(
"A mutex '" + mutexName +
"' was not already unlocked in the destructor!") {}
63 std::string
name()
const override
65 return "armarx::exceptions::local::MutexDestructionException";
83 boost::timed_mutex timedMutex;
85 std::string mutexName;
93 std::cout <<
"A mutex ('" << mutexName <<
"') was still locked in the destructor! Fix Application!\nBacktrace:\n" << LocalException::generateBacktrace() << std::endl;
103 boost::system_time timeout = boost::get_system_time() +
104 boost::posix_time::milliseconds(timeoutDelayMs);
106 if (!timedMutex.timed_lock(timeout))
114 return timedMutex.try_lock();