251#include <system_error>
258template <
typename MutexT>
289 template <
typename Rep,
typename Period>
291 const std::chrono::duration<Rep, Period>& _timeout_duration)
295 _lock_deferred(_timeout_duration);
302 template <
typename Clock,
typename Duration>
304 const std::chrono::time_point<Clock, Duration>& _timeout_time)
308 _lock_deferred(_timeout_time);
353#define _is_stand_mutex(Tp) (std::is_same<Tp, Mutex>::value)
354#define _is_recur_mutex(Tp) (std::is_same<Tp, RecursiveMutex>::value)
355#define _is_other_mutex(Tp) (!_is_stand_mutex(Tp) && !_is_recur_mutex(Tp))
357 template <
typename Tp = MutexT,
359 std::string GetTypeString()
361 return "AutoLock<Mutex>";
364 template <
typename Tp = MutexT,
366 std::string GetTypeString()
368 return "AutoLock<RecursiveMutex>";
371 template <
typename Tp = MutexT,
373 std::string GetTypeString()
375 return "AutoLock<UNKNOWN_MUTEX>";
379#undef _is_stand_mutex
380#undef _is_recur_mutex
381#undef _is_other_mutex
384 template <
typename Tp>
385 void suppress_unused_variable(
const Tp&)
408 inline void _lock_deferred()
412 this->unique_lock_t::lock();
413 }
catch(std::system_error& e)
415 PrintLockErrorMessage(e);
424 template <
typename Rep,
typename Period>
425 void _lock_deferred(
const std::chrono::duration<Rep, Period>& _timeout_duration)
429 this->unique_lock_t::try_lock_for(_timeout_duration);
430 }
catch(std::system_error& e)
432 PrintLockErrorMessage(e);
441 template <
typename Clock,
typename Duration>
442 void _lock_deferred(
const std::chrono::time_point<Clock, Duration>& _timeout_time)
446 this->unique_lock_t::try_lock_until(_timeout_time);
447 }
catch(std::system_error& e)
449 PrintLockErrorMessage(e);
456 void PrintLockErrorMessage(std::system_error& e)
463 cout <<
"Non-critical error: mutex lock failure in "
464 << GetTypeString<mutex_type>() <<
". "
465 <<
"If the app is terminating, Tasking failed to "
466 <<
"delete an allocated resource and a Tasking destructor is "
467 <<
"being called after the statics were destroyed. \n\t--> "
468 <<
"Exception: [code: " << e.code() <<
"] caught: " << e.what() << std::endl;
470 suppress_unused_variable(e);
488template <
typename Tp>
#define _is_other_mutex(Tp)
#define _is_stand_mutex(Tp)
#define _is_recur_mutex(Tp)
TemplateAutoLock(mutex_type *_mutex, std::try_to_lock_t _lock)
TemplateAutoLock(mutex_type &_mutex, std::defer_lock_t _lock) noexcept
TemplateAutoLock(mutex_type *_mutex)
unique_lock_t::mutex_type mutex_type
TemplateAutoLock< MutexT > this_type
TemplateAutoLock(mutex_type &_mutex, std::try_to_lock_t _lock)
TemplateAutoLock(mutex_type &_mutex, const std::chrono::duration< Rep, Period > &_timeout_duration)
TemplateAutoLock(mutex_type *_mutex, std::defer_lock_t _lock) noexcept
std::unique_lock< MutexT > unique_lock_t
TemplateAutoLock(mutex_type *_mutex, std::adopt_lock_t _lock)
TemplateAutoLock(mutex_type &_mutex, std::adopt_lock_t _lock)
TemplateAutoLock(mutex_type &_mutex)
TemplateAutoLock(mutex_type &_mutex, const std::chrono::time_point< Clock, Duration > &_timeout_time)
TemplateAutoLock< RecursiveMutex > RecursiveAutoLock
TemplateAutoLock< Mutex > AutoLock