mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(thread): add SSemaphore::Signal
This commit is contained in:
parent
6437796094
commit
34e01acca5
2 changed files with 29 additions and 0 deletions
|
|
@ -13,3 +13,31 @@ SSemaphore::SSemaphore(uint32_t initialCount, uint32_t maximumCount)
|
|||
pthread_cond_init(&this->m_cond, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t SSemaphore::Signal(uint32_t count) {
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
return ReleaseSemaphore(this->m_opaqueData, count, nullptr);
|
||||
#endif
|
||||
|
||||
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
||||
pthread_mutex_lock(&this->m_mutex);
|
||||
|
||||
if (this->m_value1 + count > this->m_value2) {
|
||||
pthread_mutex_unlock(&this->m_mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->m_value1 += count;
|
||||
|
||||
if (count <= 1) {
|
||||
pthread_cond_signal(&this->m_cond);
|
||||
} else {
|
||||
pthread_cond_broadcast(&this->m_cond);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&this->m_mutex);
|
||||
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue