feat(thread): add CSRWLock

This commit is contained in:
fallenoak 2020-11-01 23:13:02 -06:00
parent 3b9f061244
commit 26d78adf7a
No known key found for this signature in database
GPG key ID: 7628F8E61AEA070D
3 changed files with 52 additions and 0 deletions

View file

@ -1,6 +1,7 @@
#ifndef STORM_THREAD_HPP
#define STORM_THREAD_HPP
#include "storm/thread/CSRWLock.hpp"
#include "storm/thread/SCritSect.hpp"
#include "storm/thread/SEvent.hpp"
#include "storm/thread/SSyncObject.hpp"

25
storm/thread/CSRWLock.cpp Normal file
View 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
View 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