mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 10:32:29 +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);
|
pthread_cond_init(&this->m_cond, 0);
|
||||||
#endif
|
#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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ class SSemaphore : public SSyncObject {
|
||||||
public:
|
public:
|
||||||
// Member functions
|
// Member functions
|
||||||
SSemaphore(uint32_t initialCount, uint32_t maximumCount);
|
SSemaphore(uint32_t initialCount, uint32_t maximumCount);
|
||||||
|
int32_t Signal(uint32_t count);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue