diff --git a/CommonLibSF/include/RE/B/BSLock.h b/CommonLibSF/include/RE/B/BSLock.h index 8462595c..4b85abdf 100644 --- a/CommonLibSF/include/RE/B/BSLock.h +++ b/CommonLibSF/include/RE/B/BSLock.h @@ -2,36 +2,26 @@ namespace RE { - class BSReadWriteLock + class BSNonReentrantSpinLock { public: - void lock_read() - { - using func_t = decltype(&BSReadWriteLock::lock_read); - REL::Relocation 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{ REL::ID(34125) }; - return func(this); - } - - void unlock_read() - { - using func_t = decltype(&BSReadWriteLock::unlock_read); - REL::Relocation 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{ REL::ID(34257) }; - return func(this); - } + class BSReadWriteLock + { + public: + void lock_read(); + void lock_write(); + void unlock_read(); + void unlock_write(); private: // members @@ -43,27 +33,12 @@ namespace RE class BSSpinLock { public: - void lock() - { - using func_t = decltype(&BSSpinLock::lock); - REL::Relocation func{ REL::ID(178543) }; - return func(this); - } - - [[nodiscard]] bool try_lock() - { - using func_t = decltype(&BSSpinLock::try_lock); - REL::Relocation func{ REL::ID(178545) }; - return func(this); - } - - void unlock() - { - using func_t = decltype(&BSSpinLock::unlock); - REL::Relocation 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 }; @@ -128,7 +103,7 @@ namespace RE // members mutex_type* _lock{ nullptr }; // 00 }; - static_assert(sizeof(BSAutoLock) == 0x8); + static_assert(sizeof(BSAutoLock) == 0x8); template BSAutoLock(Mutex&) -> BSAutoLock; diff --git a/CommonLibSF/src/RE/B/BSLock.cpp b/CommonLibSF/src/RE/B/BSLock.cpp new file mode 100644 index 00000000..f3a8f2b9 --- /dev/null +++ b/CommonLibSF/src/RE/B/BSLock.cpp @@ -0,0 +1,74 @@ +#include "RE/B/BSLock.h" + +namespace RE +{ + void BSNonReentrantSpinLock::lock() + { + using func_t = decltype(&BSNonReentrantSpinLock::lock); + REL::Relocation func{ REL::ID(73879) }; + return func(this); + } + + bool BSNonReentrantSpinLock::try_lock() + { + using func_t = decltype(&BSNonReentrantSpinLock::try_lock); + REL::Relocation func{ REL::ID(74235) }; + return func(this); + } + + void BSNonReentrantSpinLock::unlock() + { + using func_t = decltype(&BSNonReentrantSpinLock::unlock); + REL::Relocation func{ REL::ID(73895) }; + return func(this); + } + + void BSReadWriteLock::lock_read() + { + using func_t = decltype(&BSReadWriteLock::lock_read); + REL::Relocation func{ REL::ID(178605) }; + return func(this); + } + + void BSReadWriteLock::lock_write() + { + using func_t = decltype(&BSReadWriteLock::lock_write); + REL::Relocation func{ REL::ID(34125) }; + return func(this); + } + + void BSReadWriteLock::unlock_read() + { + using func_t = decltype(&BSReadWriteLock::unlock_read); + REL::Relocation func{ REL::ID(178609) }; + return func(this); + } + + void BSReadWriteLock::unlock_write() + { + using func_t = decltype(&BSReadWriteLock::unlock_write); + REL::Relocation func{ REL::ID(34257) }; + return func(this); + } + + void BSSpinLock::lock() + { + using func_t = decltype(&BSSpinLock::lock); + REL::Relocation func{ REL::ID(178543) }; + return func(this); + } + + bool BSSpinLock::try_lock() + { + using func_t = decltype(&BSSpinLock::try_lock); + REL::Relocation func{ REL::ID(178545) }; + return func(this); + } + + void BSSpinLock::unlock() + { + using func_t = decltype(&BSSpinLock::unlock); + REL::Relocation func{ REL::ID(178544) }; + return func(this); + } +}