mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(thread): add CSRWLock
This commit is contained in:
parent
3b9f061244
commit
26d78adf7a
3 changed files with 52 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef STORM_THREAD_HPP
|
#ifndef STORM_THREAD_HPP
|
||||||
#define STORM_THREAD_HPP
|
#define STORM_THREAD_HPP
|
||||||
|
|
||||||
|
#include "storm/thread/CSRWLock.hpp"
|
||||||
#include "storm/thread/SCritSect.hpp"
|
#include "storm/thread/SCritSect.hpp"
|
||||||
#include "storm/thread/SEvent.hpp"
|
#include "storm/thread/SEvent.hpp"
|
||||||
#include "storm/thread/SSyncObject.hpp"
|
#include "storm/thread/SSyncObject.hpp"
|
||||||
|
|
|
||||||
25
storm/thread/CSRWLock.cpp
Normal file
25
storm/thread/CSRWLock.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#include "storm/thread/CSRWLock.hpp"
|
||||||
|
|
||||||
|
void CSRWLock::Enter(int32_t forwriting) {
|
||||||
|
#ifdef PLATFORM_WIN
|
||||||
|
// TODO
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX)
|
||||||
|
if (forwriting) {
|
||||||
|
pthread_rwlock_wrlock(&this->m_lock);
|
||||||
|
} else {
|
||||||
|
pthread_rwlock_rdlock(&this->m_lock);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSRWLock::Leave(int32_t fromwriting) {
|
||||||
|
#ifdef PLATFORM_WIN
|
||||||
|
// TODO
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX)
|
||||||
|
pthread_rwlock_unlock(&this->m_lock);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
26
storm/thread/CSRWLock.hpp
Normal file
26
storm/thread/CSRWLock.hpp
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef STORM_THREAD_CS_RW_LOCK_HPP
|
||||||
|
#define STORM_THREAD_CS_RW_LOCK_HPP
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX)
|
||||||
|
#include <pthread.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class CSRWLock {
|
||||||
|
public:
|
||||||
|
// Member variables
|
||||||
|
#ifdef PLATFORM_WIN
|
||||||
|
char m_opaqueData[12];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX)
|
||||||
|
pthread_rwlock_t m_lock;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Member functions
|
||||||
|
void Enter(int32_t forwriting);
|
||||||
|
void Leave(int32_t fromwriting);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue