Skip to content

Commit

Permalink
feat: add BSNonReentrantSpinLock
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 committed Oct 19, 2023
1 parent bc267f4 commit ed26a15
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 47 deletions.
69 changes: 22 additions & 47 deletions CommonLibSF/include/RE/B/BSLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,26 @@

namespace RE
{
class BSReadWriteLock
class BSNonReentrantSpinLock
{
public:
void lock_read()
{
using func_t = decltype(&BSReadWriteLock::lock_read);
REL::Relocation<func_t> func{ REL::ID(178605) };
return func(this);
}
void lock();
[[nodiscard]] bool try_lock();
void unlock();

void lock_write()
{
using func_t = decltype(&BSReadWriteLock::lock_write);
REL::Relocation<func_t> func{ REL::ID(34125) };
return func(this);
}

void unlock_read()
{
using func_t = decltype(&BSReadWriteLock::unlock_read);
REL::Relocation<func_t> func{ REL::ID(178609) };
return func(this);
}
private:
// members
volatile std::uint32_t _lock{ 0 }; // 0
};
static_assert(sizeof(BSNonReentrantSpinLock) == 0x4);

void unlock_write()
{
using func_t = decltype(&BSReadWriteLock::unlock_write);
REL::Relocation<func_t> func{ REL::ID(34257) };
return func(this);
}
class BSReadWriteLock
{
public:
void lock_read();
void lock_write();
void unlock_read();
void unlock_write();

private:
// members
Expand All @@ -43,27 +33,12 @@ namespace RE
class BSSpinLock
{
public:
void lock()
{
using func_t = decltype(&BSSpinLock::lock);
REL::Relocation<func_t> func{ REL::ID(178543) };
return func(this);
}

[[nodiscard]] bool try_lock()
{
using func_t = decltype(&BSSpinLock::try_lock);
REL::Relocation<func_t> func{ REL::ID(178545) };
return func(this);
}

void unlock()
{
using func_t = decltype(&BSSpinLock::unlock);
REL::Relocation<func_t> func{ REL::ID(178544) };
return func(this);
}
void lock();
[[nodiscard]] bool try_lock();
void unlock();

private:
// members
std::uint32_t _owningThread{ 0 }; // 0
volatile std::uint32_t _lock{ 0 }; // 4
};
Expand Down Expand Up @@ -128,7 +103,7 @@ namespace RE
// members
mutex_type* _lock{ nullptr }; // 00
};
static_assert(sizeof(BSAutoLock<BSSpinLock>) == 0x8);
static_assert(sizeof(BSAutoLock<void*>) == 0x8);

template <class Mutex>
BSAutoLock(Mutex&) -> BSAutoLock<Mutex>;
Expand Down
74 changes: 74 additions & 0 deletions CommonLibSF/src/RE/B/BSLock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "RE/B/BSLock.h"

namespace RE
{
void BSNonReentrantSpinLock::lock()
{
using func_t = decltype(&BSNonReentrantSpinLock::lock);
REL::Relocation<func_t> func{ REL::ID(73879) };
return func(this);
}

bool BSNonReentrantSpinLock::try_lock()
{
using func_t = decltype(&BSNonReentrantSpinLock::try_lock);
REL::Relocation<func_t> func{ REL::ID(74235) };
return func(this);
}

void BSNonReentrantSpinLock::unlock()
{
using func_t = decltype(&BSNonReentrantSpinLock::unlock);
REL::Relocation<func_t> func{ REL::ID(73895) };
return func(this);
}

void BSReadWriteLock::lock_read()
{
using func_t = decltype(&BSReadWriteLock::lock_read);
REL::Relocation<func_t> func{ REL::ID(178605) };
return func(this);
}

BSReadWriteLock::lock_write()
{
using func_t = decltype(&BSReadWriteLock::lock_write);
REL::Relocation<func_t> func{ REL::ID(34125) };
return func(this);
}

void BSReadWriteLock::unlock_read()
{
using func_t = decltype(&BSReadWriteLock::unlock_read);
REL::Relocation<func_t> func{ REL::ID(178609) };
return func(this);
}

void BSReadWriteLock::unlock_write()
{
using func_t = decltype(&BSReadWriteLock::unlock_write);
REL::Relocation<func_t> func{ REL::ID(34257) };
return func(this);
}

void BSSpinLock::lock()
{
using func_t = decltype(&BSSpinLock::lock);
REL::Relocation<func_t> func{ REL::ID(178543) };
return func(this);
}

bool BSSpinLock::try_lock()
{
using func_t = decltype(&BSSpinLock::try_lock);
REL::Relocation<func_t> func{ REL::ID(178545) };
return func(this);
}

void BSSpinLock::unlock()
{
using func_t = decltype(&BSSpinLock::unlock);
REL::Relocation<func_t> func{ REL::ID(178544) };
return func(this);
}
}

0 comments on commit ed26a15

Please sign in to comment.