mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 18:42:28 +00:00
fix(thread): correct layout of SSyncObject
This commit is contained in:
parent
0d00bd3ae4
commit
83cd9b05c0
6 changed files with 25 additions and 24 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ uint32_t S_Thread::s_SLaunchThread(void* threadParam) {
|
|||
|
||||
if (params->syncObject) {
|
||||
pthread_mutex_lock(¶ms->syncObject->m_mutex);
|
||||
params->syncObject->m_value = 1;
|
||||
params->syncObject->m_value1 = 1;
|
||||
pthread_mutex_unlock(¶ms->syncObject->m_mutex);
|
||||
pthread_cond_signal(¶ms->syncObject->m_cond);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue