2020-11-01 17:45:45 -06:00
|
|
|
#include "storm/thread/SEvent.hpp"
|
2020-09-09 00:45:46 -05:00
|
|
|
|
|
|
|
|
SEvent::SEvent(int32_t manualReset, int32_t initialValue)
|
|
|
|
|
: SSyncObject() {
|
2020-11-24 17:29:31 -06:00
|
|
|
#if defined(WHOA_PLATFORM_WIN)
|
2020-09-09 00:45:46 -05:00
|
|
|
this->m_opaqueData = CreateEventA(nullptr, manualReset, initialValue, nullptr);
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-11-24 17:29:31 -06:00
|
|
|
#if defined(WHOA_PLATFORM_MAC) || defined(WHOA_PLATFORM_LINUX)
|
2020-09-09 00:45:46 -05:00
|
|
|
this->m_int0 = 2 - (manualReset >= 1);
|
|
|
|
|
this->m_value = initialValue;
|
|
|
|
|
|
|
|
|
|
pthread_cond_init(&this->m_cond, nullptr);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t SEvent::Reset() {
|
2020-11-24 17:29:31 -06:00
|
|
|
#if defined(WHOA_PLATFORM_WIN)
|
2020-09-09 00:45:46 -05:00
|
|
|
return ResetEvent(this->m_opaqueData);
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-11-24 17:29:31 -06:00
|
|
|
#if defined(WHOA_PLATFORM_MAC) || defined(WHOA_PLATFORM_LINUX)
|
2020-09-09 00:45:46 -05:00
|
|
|
pthread_mutex_lock(&this->m_mutex);
|
|
|
|
|
this->m_value = 0;
|
|
|
|
|
pthread_mutex_unlock(&this->m_mutex);
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t SEvent::Set() {
|
2020-11-24 17:29:31 -06:00
|
|
|
#if defined(WHOA_PLATFORM_WIN)
|
2020-09-09 00:45:46 -05:00
|
|
|
return SetEvent(this->m_opaqueData);
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-11-24 17:29:31 -06:00
|
|
|
#if defined(WHOA_PLATFORM_MAC) || defined(WHOA_PLATFORM_LINUX)
|
2020-09-09 00:45:46 -05:00
|
|
|
pthread_mutex_lock(&this->m_mutex);
|
|
|
|
|
|
|
|
|
|
this->m_value = 1;
|
|
|
|
|
pthread_cond_signal(&this->m_cond);
|
|
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&this->m_mutex);
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
#endif
|
|
|
|
|
}
|