298#define TMCMULTITHREADED 1
304#include <system_error>
319#define TMCMUTEX_INITIALIZER \
322#if defined(TMCMULTITHREADED)
324#define TMCMUTEXLOCK(mutex) \
328#define TMCMUTEXUNLOCK(mutex) \
334#define TMCMUTEXLOCK(mutex) \
336#define TMCMUTEXUNLOCK(mutex) \
343template <
typename _Mutex_t>
374 template <
typename Rep,
typename Period>
377 const std::chrono::duration<Rep, Period>& _timeout_duration)
388 template <
typename Clock,
typename Duration>
391 const std::chrono::time_point<Clock, Duration>& _timeout_time)
403#ifdef TMCMULTITHREADED
446#if defined(TMCMULTITHREADED)
473#if defined(TMCMULTITHREADED)
483 bool try_lock() {
return true; }
485 template <
typename Rep,
typename Period>
486 bool try_lock_for(
const std::chrono::duration<Rep, Period>&)
491 template <
typename Clock,
typename Duration>
492 bool try_lock_until(
const std::chrono::time_point<Clock, Duration>&)
497 void swap(
this_type& other)
noexcept { std::swap(*
this, other); }
498 bool owns_lock() const noexcept {
return false; }
510#define _is_stand_mutex(_Tp) (std::is_same<_Tp, TMCMutex>::value)
511#define _is_recur_mutex(_Tp) (std::is_same<_Tp, TMCRecursiveMutex>::value)
512#define _is_other_mutex(_Tp) (!_is_stand_mutex(_Tp) && !_is_recur_mutex(_Tp))
514 template <
typename _Tp = _Mutex_t,
518 return "TMCAutoLock<TMCMutex>";
521 template <
typename _Tp = _Mutex_t,
525 return "TMCAutoLock<TMCRecursiveMutex>";
528 template <
typename _Tp = _Mutex_t,
532 return "TMCAutoLock<UNKNOWN_MUTEX>";
536#undef _is_stand_mutex
537#undef _is_recur_mutex
538#undef _is_other_mutex
541 template <
typename _Tp>
567#if defined(TMCMULTITHREADED)
570 this->unique_lock_t::lock();
571 }
catch(std::system_error& e)
583 template <
typename Rep,
typename Period>
585 const std::chrono::duration<Rep, Period>& _timeout_duration)
587#if defined(TMCMULTITHREADED)
590 this->unique_lock_t::try_lock_for(_timeout_duration);
591 }
catch(std::system_error& e)
605 template <
typename Clock,
typename Duration>
607 const std::chrono::time_point<Clock, Duration>& _timeout_time)
609#if defined(TMCMULTITHREADED)
612 this->unique_lock_t::try_lock_until(_timeout_time);
613 }
catch(std::system_error& e)
631 cout <<
"Non-critical error: mutex lock failure in "
632 << GetTypeString<mutex_type>() <<
". "
633 <<
"If the app is terminating, Geant4 failed to "
634 <<
"delete an allocated resource and a Geant4 destructor is "
635 <<
"being called after the statics were destroyed. \n\t--> "
636 <<
"Exception: [code: " << e.code() <<
"] caught: " << e.what()
655template <
typename _Tp>
#define _is_recur_mutex(_Tp)
int(*)(TMCMutex *) thread_lock
#define _is_stand_mutex(_Tp)
int(*)(TMCMutex *) thread_unlock
std::recursive_mutex TMCRecursiveMutex
#define _is_other_mutex(_Tp)
TMCTemplateAutoLock(mutex_type &_mutex)
void PrintLockErrorMessage(std::system_error &e)
TMCTemplateAutoLock(mutex_type *_mutex, std::defer_lock_t _lock) noexcept
std::string GetTypeString()
TMCTemplateAutoLock(mutex_type &_mutex, std::adopt_lock_t _lock)
void _lock_deferred(const std::chrono::duration< Rep, Period > &_timeout_duration)
TMCTemplateAutoLock(mutex_type &_mutex, std::defer_lock_t _lock) noexcept
TMCTemplateAutoLock(mutex_type &_mutex, const std::chrono::time_point< Clock, Duration > &_timeout_time)
TMCTemplateAutoLock(mutex_type &_mutex, const std::chrono::duration< Rep, Period > &_timeout_duration)
void suppress_unused_variable(const _Tp &)
TMCTemplateAutoLock(mutex_type *_mutex)
void _lock_deferred(const std::chrono::time_point< Clock, Duration > &_timeout_time)
TMCTemplateAutoLock(mutex_type *_mutex, std::adopt_lock_t _lock)
TMCTemplateAutoLock(mutex_type *_mutex, std::try_to_lock_t _lock)
unique_lock_t::mutex_type mutex_type
TMCTemplateAutoLock(mutex_type &_mutex, std::try_to_lock_t _lock)
TMCTemplateAutoLock< _Mutex_t > this_type
std::unique_lock< _Mutex_t > unique_lock_t