mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 10:32:29 +00:00
feat(thread): add CCritSect
This commit is contained in:
parent
368c2f16c2
commit
a500c34d45
4 changed files with 90 additions and 0 deletions
41
storm/thread/CCritSect.cpp
Normal file
41
storm/thread/CCritSect.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include "storm/thread/CCritSect.hpp"
|
||||
|
||||
CCritSect::CCritSect() {
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
InitializeCriticalSection(&this->m_critsect);
|
||||
#endif
|
||||
|
||||
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
||||
pthread_mutex_init(&this->m_critsect, nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
CCritSect::~CCritSect() {
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
DeleteCriticalSection(&this->m_critsect);
|
||||
#endif
|
||||
|
||||
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
||||
pthread_mutex_destroy(&this->m_critsect);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CCritSect::Enter() {
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
EnterCriticalSection(&this->m_critsect);
|
||||
#endif
|
||||
|
||||
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
||||
pthread_mutex_lock(&this->m_critsect);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CCritSect::Leave() {
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
LeaveCriticalSection(&this->m_critsect);
|
||||
#endif
|
||||
|
||||
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
||||
pthread_mutex_unlock(&this->m_critsect);
|
||||
#endif
|
||||
}
|
||||
31
storm/thread/CCritSect.hpp
Normal file
31
storm/thread/CCritSect.hpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef STORM_THREAD_C_CRIT_SECT_HPP
|
||||
#define STORM_THREAD_C_CRIT_SECT_HPP
|
||||
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
class CCritSect {
|
||||
public:
|
||||
// Member functions
|
||||
CCritSect();
|
||||
~CCritSect();
|
||||
void Enter();
|
||||
void Leave();
|
||||
|
||||
private:
|
||||
// Member variables
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
CRITICAL_SECTION m_critsect;
|
||||
#endif
|
||||
|
||||
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
||||
pthread_mutex_t m_critsect;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue