2020-11-01 17:45:45 -06:00
|
|
|
#include "storm/thread/SCritSect.hpp"
|
2020-09-09 00:45:46 -05:00
|
|
|
|
2022-12-28 15:43:57 -06:00
|
|
|
SCritSect::SCritSect() {
|
|
|
|
|
#if defined(WHOA_SYSTEM_WIN)
|
|
|
|
|
InitializeCriticalSection(&this->m_opaqueData);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
|
|
|
|
pthread_mutexattr_t attr;
|
|
|
|
|
pthread_mutexattr_init(&attr);
|
|
|
|
|
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
|
|
|
|
|
|
|
|
|
pthread_mutex_init(&this->m_mutex, &attr);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-28 15:54:37 -06:00
|
|
|
SCritSect::~SCritSect() {
|
|
|
|
|
#if defined(WHOA_SYSTEM_WIN)
|
|
|
|
|
DeleteCriticalSection(&this->m_opaqueData);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
|
|
|
|
pthread_mutex_destroy(&this->m_mutex);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-09 00:45:46 -05:00
|
|
|
void SCritSect::Enter() {
|
2020-12-02 20:04:02 -06:00
|
|
|
#if defined(WHOA_SYSTEM_WIN)
|
2020-09-09 00:45:46 -05:00
|
|
|
EnterCriticalSection(&this->m_opaqueData);
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-12-02 20:04:02 -06:00
|
|
|
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
2020-09-09 00:45:46 -05:00
|
|
|
pthread_mutex_lock(&this->m_mutex);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SCritSect::Leave() {
|
2020-12-02 20:04:02 -06:00
|
|
|
#if defined(WHOA_SYSTEM_WIN)
|
2020-09-09 00:45:46 -05:00
|
|
|
LeaveCriticalSection(&this->m_opaqueData);
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-12-02 20:04:02 -06:00
|
|
|
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
2020-09-09 00:45:46 -05:00
|
|
|
pthread_mutex_unlock(&this->m_mutex);
|
|
|
|
|
#endif
|
|
|
|
|
}
|