31 #include <system_error>
39 #if (AI_BUILD_TYPE == AI_RELEASE)
40 #define __MutexThrowOnError(err) \
43 #elif (AI_BUILD_TYPE == AI_DEBUG)
44 #define __MutexThrowOnError(err) \
46 if (__builtin_expect((err != 0), 0)) \
47 throw std::system_error(std::error_code(err, std::system_category())); \
51 #error Unknown AI build type
71 #if (AI_BUILD_TYPE == AI_DEBUG)
72 pthread_mutexattr_t attr;
73 pthread_mutexattr_init(&attr);
74 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
75 pthread_mutex_init(&mLock, &attr);
76 pthread_mutexattr_destroy(&attr);
77 #elif (AI_BUILD_TYPE == AI_RELEASE)
78 pthread_mutex_init(&mLock,
nullptr);
80 #error Unknown AI build type
89 int err = pthread_mutex_destroy(&mLock);
92 __MutexThrowOnError(err);
94 catch(
const std::system_error& exception)
96 AI_LOG_FATAL(
"Mutex failed to be destroyed %s", exception.what());
103 int err = pthread_mutex_lock(&mLock);
104 __MutexThrowOnError(err);
109 int err = pthread_mutex_unlock(&mLock);
110 __MutexThrowOnError(err);
115 int err = pthread_mutex_trylock(&mLock);
120 else if (err == EBUSY)
126 __MutexThrowOnError(err);
132 typedef pthread_mutex_t* native_handle_type;
133 native_handle_type native_handle()
139 pthread_mutex_t mLock;