feat: improve fast crit section
This commit is contained in:
parent
6b9bba991f
commit
dadaca86b2
41
src/game/engine/fast_critical_section.cpp
Normal file
41
src/game/engine/fast_critical_section.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include <std_include.hpp>
|
||||||
|
#include "game/game.hpp"
|
||||||
|
|
||||||
|
#include "fast_critical_section.hpp"
|
||||||
|
|
||||||
|
namespace game::engine
|
||||||
|
{
|
||||||
|
FastCriticalSectionScopeRead::FastCriticalSectionScopeRead(native::FastCriticalSection* cs)
|
||||||
|
{
|
||||||
|
this->cs_ = cs;
|
||||||
|
if (this->cs_)
|
||||||
|
{
|
||||||
|
native::Sys_LockRead(this->cs_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FastCriticalSectionScopeRead::~FastCriticalSectionScopeRead()
|
||||||
|
{
|
||||||
|
if (this->cs_)
|
||||||
|
{
|
||||||
|
native::Sys_UnlockRead(this->cs_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FastCriticalSectionScopeWrite::FastCriticalSectionScopeWrite(native::FastCriticalSection* cs)
|
||||||
|
{
|
||||||
|
this->cs_ = cs;
|
||||||
|
if (this->cs_)
|
||||||
|
{
|
||||||
|
native::Sys_LockWrite(this->cs_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FastCriticalSectionScopeWrite::~FastCriticalSectionScopeWrite()
|
||||||
|
{
|
||||||
|
if (this->cs_)
|
||||||
|
{
|
||||||
|
native::Sys_UnlockWrite(this->cs_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
src/game/engine/fast_critical_section.hpp
Normal file
24
src/game/engine/fast_critical_section.hpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace game::engine
|
||||||
|
{
|
||||||
|
class FastCriticalSectionScopeRead
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FastCriticalSectionScopeRead(native::FastCriticalSection* cs);
|
||||||
|
~FastCriticalSectionScopeRead();
|
||||||
|
|
||||||
|
private:
|
||||||
|
native::FastCriticalSection* cs_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FastCriticalSectionScopeWrite
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FastCriticalSectionScopeWrite(native::FastCriticalSection* cs);
|
||||||
|
~FastCriticalSectionScopeWrite();
|
||||||
|
|
||||||
|
private:
|
||||||
|
native::FastCriticalSection* cs_;
|
||||||
|
};
|
||||||
|
}
|
@ -72,6 +72,8 @@ namespace game
|
|||||||
Sys_Sleep_t Sys_Sleep;
|
Sys_Sleep_t Sys_Sleep;
|
||||||
Sys_FreeFileList_t Sys_FreeFileList;
|
Sys_FreeFileList_t Sys_FreeFileList;
|
||||||
Sys_MessageBox_t Sys_MessageBox;
|
Sys_MessageBox_t Sys_MessageBox;
|
||||||
|
Sys_LockWrite_t Sys_LockWrite;
|
||||||
|
Sys_TempPriorityEnd_t Sys_TempPriorityEnd;
|
||||||
|
|
||||||
PMem_AllocFromSource_NoDebug_t PMem_AllocFromSource_NoDebug;
|
PMem_AllocFromSource_NoDebug_t PMem_AllocFromSource_NoDebug;
|
||||||
|
|
||||||
@ -569,6 +571,13 @@ namespace game
|
|||||||
InterlockedDecrement(&critSect->readCount);
|
InterlockedDecrement(&critSect->readCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sys_UnlockWrite(FastCriticalSection* critSect)
|
||||||
|
{
|
||||||
|
assert(critSect->writeCount > 0);
|
||||||
|
InterlockedDecrement(&critSect->writeCount);
|
||||||
|
Sys_TempPriorityEnd(&critSect->tempPriority);
|
||||||
|
}
|
||||||
|
|
||||||
[[noreturn]] void Sys_OutOfMemErrorInternal(const char* filename, int line)
|
[[noreturn]] void Sys_OutOfMemErrorInternal(const char* filename, int line)
|
||||||
{
|
{
|
||||||
Sys_EnterCriticalSection(CRITSECT_FATAL_ERROR);
|
Sys_EnterCriticalSection(CRITSECT_FATAL_ERROR);
|
||||||
@ -801,6 +810,8 @@ namespace game
|
|||||||
native::Sys_Sleep = native::Sys_Sleep_t(SELECT_VALUE(0x438600, 0x55F460));
|
native::Sys_Sleep = native::Sys_Sleep_t(SELECT_VALUE(0x438600, 0x55F460));
|
||||||
native::Sys_FreeFileList = native::Sys_FreeFileList_t(SELECT_VALUE(0x486380, 0x5C4F90));
|
native::Sys_FreeFileList = native::Sys_FreeFileList_t(SELECT_VALUE(0x486380, 0x5C4F90));
|
||||||
native::Sys_MessageBox = native::Sys_MessageBox_t(SELECT_VALUE(0x4664D0, 0x5CD180));
|
native::Sys_MessageBox = native::Sys_MessageBox_t(SELECT_VALUE(0x4664D0, 0x5CD180));
|
||||||
|
native::Sys_LockWrite = native::Sys_LockWrite_t(SELECT_VALUE(0x4C9E70, 0x5502D0));
|
||||||
|
native::Sys_TempPriorityEnd = native::Sys_TempPriorityEnd_t(SELECT_VALUE(0x4DCF00, 0x4C8CF0));
|
||||||
|
|
||||||
native::PMem_AllocFromSource_NoDebug = native::PMem_AllocFromSource_NoDebug_t(SELECT_VALUE(0x449E50, 0x5C15C0));
|
native::PMem_AllocFromSource_NoDebug = native::PMem_AllocFromSource_NoDebug_t(SELECT_VALUE(0x449E50, 0x5C15C0));
|
||||||
|
|
||||||
|
@ -164,6 +164,12 @@ namespace game
|
|||||||
typedef int (*Sys_MessageBox_t)(const char* lpText, const char* lpCaption, unsigned int uType, int defaultValue);
|
typedef int (*Sys_MessageBox_t)(const char* lpText, const char* lpCaption, unsigned int uType, int defaultValue);
|
||||||
extern Sys_MessageBox_t Sys_MessageBox;
|
extern Sys_MessageBox_t Sys_MessageBox;
|
||||||
|
|
||||||
|
typedef void (*Sys_LockWrite_t)(FastCriticalSection* critSect);
|
||||||
|
extern Sys_LockWrite_t Sys_LockWrite;
|
||||||
|
|
||||||
|
typedef void (*Sys_TempPriorityEnd_t)(TempPriority*);
|
||||||
|
extern Sys_TempPriorityEnd_t Sys_TempPriorityEnd;
|
||||||
|
|
||||||
typedef void* (*PMem_AllocFromSource_NoDebug_t)(unsigned int size, unsigned int alignment, unsigned int type, int source);
|
typedef void* (*PMem_AllocFromSource_NoDebug_t)(unsigned int size, unsigned int alignment, unsigned int type, int source);
|
||||||
extern PMem_AllocFromSource_NoDebug_t PMem_AllocFromSource_NoDebug;
|
extern PMem_AllocFromSource_NoDebug_t PMem_AllocFromSource_NoDebug;
|
||||||
|
|
||||||
@ -427,6 +433,7 @@ namespace game
|
|||||||
bool Sys_IsServerThread();
|
bool Sys_IsServerThread();
|
||||||
void Sys_LockRead(FastCriticalSection* critSect);
|
void Sys_LockRead(FastCriticalSection* critSect);
|
||||||
void Sys_UnlockRead(FastCriticalSection* critSect);
|
void Sys_UnlockRead(FastCriticalSection* critSect);
|
||||||
|
void Sys_UnlockWrite(FastCriticalSection* critSect);
|
||||||
[[noreturn]] void Sys_OutOfMemErrorInternal(const char* filename, int line);
|
[[noreturn]] void Sys_OutOfMemErrorInternal(const char* filename, int line);
|
||||||
|
|
||||||
bool FS_Initialized();
|
bool FS_Initialized();
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <cassert>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
Loading…
Reference in New Issue
Block a user