fix(thread): correct layout of SSyncObject

This commit is contained in:
fallenoak 2021-08-09 00:13:52 -05:00
parent 0d00bd3ae4
commit 83cd9b05c0
No known key found for this signature in database
GPG key ID: 7628F8E61AEA070D
6 changed files with 25 additions and 24 deletions

View file

@ -7,8 +7,8 @@ SEvent::SEvent(int32_t manualReset, int32_t initialValue)
#endif
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
this->m_int0 = 2 - (manualReset >= 1);
this->m_value = initialValue;
this->int0 = 2 - (manualReset >= 1);
this->m_value1 = initialValue;
pthread_cond_init(&this->m_cond, nullptr);
#endif
@ -21,7 +21,7 @@ int32_t SEvent::Reset() {
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
pthread_mutex_lock(&this->m_mutex);
this->m_value = 0;
this->m_value1 = 0;
pthread_mutex_unlock(&this->m_mutex);
return 1;
@ -36,7 +36,7 @@ int32_t SEvent::Set() {
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
pthread_mutex_lock(&this->m_mutex);
this->m_value = 1;
this->m_value1 = 1;
pthread_cond_signal(&this->m_cond);
pthread_mutex_unlock(&this->m_mutex);

View file

@ -18,7 +18,7 @@ uint32_t SSyncObject::Wait(uint32_t timeoutMs) {
#endif
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
if (this->m_int0 == 6) {
if (this->int0 == 6) {
// WAIT_FAILED
return 0xFFFFFFFF;
}
@ -70,7 +70,7 @@ uint32_t SSyncObject::Wait(uint32_t timeoutMs) {
usleep(0);
}
if (this->m_int0 == 3) {
if (this->int0 == 3) {
// WAIT_OBJECT_0
return 0;
}
@ -78,7 +78,7 @@ uint32_t SSyncObject::Wait(uint32_t timeoutMs) {
int32_t v4;
while (true) {
v4 = this->m_value;
v4 = this->m_value1;
if (v4) {
break;
@ -99,10 +99,10 @@ uint32_t SSyncObject::Wait(uint32_t timeoutMs) {
}
}
if (this->m_int0 == 2) {
this->m_value = 0;
} else if (this->m_int0 == 4) {
this->m_value = v4 - 1;
if (this->int0 == 2) {
this->m_value1 = 0;
} else if (this->int0 == 4) {
this->m_value1 = v4 - 1;
}
pthread_mutex_unlock(&this->m_mutex);
@ -113,19 +113,19 @@ uint32_t SSyncObject::Wait(uint32_t timeoutMs) {
pthread_mutex_lock(&this->m_mutex);
if (this->m_int0 == 3) {
if (this->int0 == 3) {
// WAIT_OBJECT_0
return 0;
}
while (!this->m_value) {
while (!this->m_value1) {
pthread_cond_wait(&this->m_cond, &this->m_mutex);
}
if (this->m_int0 == 2) {
this->m_value = 0;
} else if (this->m_int0 == 4) {
this->m_value = this->m_value - 1;
if (this->int0 == 2) {
this->m_value1 = 0;
} else if (this->int0 == 4) {
this->m_value1 = this->m_value1 - 1;
}
pthread_mutex_unlock(&this->m_mutex);

View file

@ -19,10 +19,11 @@ class SSyncObject {
#endif
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
int32_t m_int0 = 6;
int32_t m_value;
pthread_cond_t m_cond;
int32_t int0 = 6;
int32_t m_value1;
int32_t m_value2;
pthread_mutex_t m_mutex;
pthread_cond_t m_cond;
#endif
// Member functions

View file

@ -8,8 +8,8 @@ int32_t SThread::Create(uint32_t (*threadProc)(void*), void* param, SThread& thr
#endif
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
thread.m_int0 = 5;
thread.m_value = 0;
thread.int0 = 5;
thread.m_value1 = 0;
pthread_cond_init(&thread.m_cond, nullptr);
uint32_t v8;

View file

@ -32,7 +32,7 @@ uint32_t S_Thread::s_SLaunchThread(void* threadParam) {
if (params->syncObject) {
pthread_mutex_lock(&params->syncObject->m_mutex);
params->syncObject->m_value = 1;
params->syncObject->m_value1 = 1;
pthread_mutex_unlock(&params->syncObject->m_mutex);
pthread_cond_signal(&params->syncObject->m_cond);
}

View file

@ -48,7 +48,7 @@ int32_t SCreateThread(uint32_t (*threadProc)(void*), void* threadParam, void* a3
params->syncObject = syncObject;
if (syncObject) {
syncObject->m_value = 0;
syncObject->m_value1 = 0;
pthread_cond_init(&syncObject->m_cond, nullptr);
pthread_mutex_init(&syncObject->m_mutex, nullptr);
}