squall/storm/thread/SEvent.cpp

47 lines
1 KiB
C++
Raw Permalink Normal View History

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-12-02 20:04:02 -06:00
#if defined(WHOA_SYSTEM_WIN)
2020-09-09 00:45:46 -05:00
this->m_opaqueData = CreateEventA(nullptr, manualReset, initialValue, nullptr);
#endif
2020-12-02 20:04:02 -06:00
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
this->int0 = 2 - (manualReset >= 1);
this->m_value1 = initialValue;
2020-09-09 00:45:46 -05:00
pthread_cond_init(&this->m_cond, nullptr);
#endif
}
int32_t SEvent::Reset() {
2020-12-02 20:04:02 -06:00
#if defined(WHOA_SYSTEM_WIN)
2020-09-09 00:45:46 -05:00
return ResetEvent(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);
this->m_value1 = 0;
2020-09-09 00:45:46 -05:00
pthread_mutex_unlock(&this->m_mutex);
return 1;
#endif
}
int32_t SEvent::Set() {
2020-12-02 20:04:02 -06:00
#if defined(WHOA_SYSTEM_WIN)
2020-09-09 00:45:46 -05:00
return SetEvent(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);
this->m_value1 = 1;
2020-09-09 00:45:46 -05:00
pthread_cond_signal(&this->m_cond);
pthread_mutex_unlock(&this->m_mutex);
return 1;
#endif
}