mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(thread): add SCritSect constructor
This commit is contained in:
parent
61d2c8d01e
commit
665f057516
3 changed files with 32 additions and 0 deletions
|
|
@ -1,5 +1,19 @@
|
||||||
#include "storm/thread/SCritSect.hpp"
|
#include "storm/thread/SCritSect.hpp"
|
||||||
|
|
||||||
|
SCritSect::SCritSect() {
|
||||||
|
#if defined(WHOA_SYSTEM_WIN)
|
||||||
|
InitializeCriticalSection(&this->m_opaqueData);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
pthread_mutexattr_init(&attr);
|
||||||
|
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||||
|
|
||||||
|
pthread_mutex_init(&this->m_mutex, &attr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void SCritSect::Enter() {
|
void SCritSect::Enter() {
|
||||||
#if defined(WHOA_SYSTEM_WIN)
|
#if defined(WHOA_SYSTEM_WIN)
|
||||||
EnterCriticalSection(&this->m_opaqueData);
|
EnterCriticalSection(&this->m_opaqueData);
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ class SCritSect {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
|
SCritSect();
|
||||||
void Enter(void);
|
void Enter(void);
|
||||||
void Leave(void);
|
void Leave(void);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,20 @@ TEST_CASE("SGetCurrentThreadId", "[thread]") {
|
||||||
CHECK(threadId > 0);
|
CHECK(threadId > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("SCritSect::Enter", "[thread]") {
|
||||||
|
SECTION("locks critical section") {
|
||||||
|
SCritSect critSect;
|
||||||
|
critSect.Enter();
|
||||||
|
SUCCEED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("SCritSect::Leave", "[thread]") {
|
||||||
|
SECTION("unlocks critical section") {
|
||||||
|
SCritSect critSect;
|
||||||
|
critSect.Enter();
|
||||||
|
critSect.Leave();
|
||||||
|
SUCCEED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue