252#include <system_error>
259template <
typename MutexT>
290 template <
typename Rep,
typename Period>
292 const std::chrono::duration<Rep, Period>& _timeout_duration)
296 _lock_deferred(_timeout_duration);
303 template <
typename Clock,
typename Duration>
305 const std::chrono::time_point<Clock, Duration>& _timeout_time)
309 _lock_deferred(_timeout_time);
354#define _is_stand_mutex(Tp) (std::is_same<Tp, Mutex>::value)
355#define _is_recur_mutex(Tp) (std::is_same<Tp, RecursiveMutex>::value)
356#define _is_other_mutex(Tp) (!_is_stand_mutex(Tp) && !_is_recur_mutex(Tp))
358 template <
typename Tp = MutexT,
360 std::string GetTypeString()
362 return "AutoLock<Mutex>";
365 template <
typename Tp = MutexT,
367 std::string GetTypeString()
369 return "AutoLock<RecursiveMutex>";
372 template <
typename Tp = MutexT,
374 std::string GetTypeString()
376 return "AutoLock<UNKNOWN_MUTEX>";
380#undef _is_stand_mutex
381#undef _is_recur_mutex
382#undef _is_other_mutex
404 inline void _lock_deferred()
408 this->unique_lock_t::lock();
409 }
catch(std::system_error& e)
411 PrintLockErrorMessage(e);
420 template <
typename Rep,
typename Period>
421 void _lock_deferred(
const std::chrono::duration<Rep, Period>& _timeout_duration)
425 this->unique_lock_t::try_lock_for(_timeout_duration);
426 }
catch(std::system_error& e)
428 PrintLockErrorMessage(e);
437 template <
typename Clock,
typename Duration>
438 void _lock_deferred(
const std::chrono::time_point<Clock, Duration>& _timeout_time)
442 this->unique_lock_t::try_lock_until(_timeout_time);
443 }
catch(std::system_error& e)
445 PrintLockErrorMessage(e);
452 void PrintLockErrorMessage(std::system_error& e)
459 cout <<
"Non-critical error: mutex lock failure in "
460 << GetTypeString<mutex_type>() <<
". "
461 <<
"If the app is terminating, Tasking failed to "
462 <<
"delete an allocated resource and a Tasking destructor is "
463 <<
"being called after the statics were destroyed. \n\t--> "
464 <<
"Exception: [code: " << e.code() <<
"] caught: " << e.what() << std::endl;
#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)
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
TemplateAutoLock(mutex_type *_mutex, std::adopt_lock_t _lock)
TemplateAutoLock(mutex_type &_mutex, std::adopt_lock_t _lock)
TemplateAutoLock(mutex_type &_mutex)
typename unique_lock_t::mutex_type mutex_type
std::unique_lock< MutexT > unique_lock_t
TemplateAutoLock(mutex_type &_mutex, const std::chrono::time_point< Clock, Duration > &_timeout_time)
void ConsumeParameters(Args &&...)