aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2025-04-29 17:39:09 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2025-04-29 17:39:09 +0200
commitc3f84bfe9c37df94abaff9eaf73cba23ede32c44 (patch)
tree5f6cf341dfc33bf10f62ac51d0cd5e415d0d8c9b
parent313b2bbea87101fdd629a2a48b47c75d35b5c501 (diff)
downloadlanes-c3f84bfe9c37df94abaff9eaf73cba23ede32c44.tar.gz
lanes-c3f84bfe9c37df94abaff9eaf73cba23ede32c44.tar.bz2
lanes-c3f84bfe9c37df94abaff9eaf73cba23ede32c44.zip
Move ProtectedAllocator::Protected_lua_Alloc in universe.cpp
-rw-r--r--src/universe.cpp10
-rw-r--r--src/universe.hpp11
2 files changed, 13 insertions, 8 deletions
diff --git a/src/universe.cpp b/src/universe.cpp
index 0f41585..06f7f21 100644
--- a/src/universe.cpp
+++ b/src/universe.cpp
@@ -51,6 +51,16 @@ static constexpr RegistryUniqueKey kUniverseFullRegKey{ 0x1C2D76870DD9DD9Full };
51 51
52// ################################################################################################# 52// #################################################################################################
53 53
54[[nodiscard]]
55void* ProtectedAllocator::Protected_lua_Alloc(void* const ud_, void* const ptr_, size_t const osize_, size_t const nsize_)
56{
57 ProtectedAllocator* const _allocator{ static_cast<ProtectedAllocator*>(ud_) };
58 std::lock_guard<std::mutex> _guard{ _allocator->mutex };
59 return _allocator->alloc(ptr_, osize_, nsize_);
60}
61
62// #################################################################################################
63
54Universe::Universe() 64Universe::Universe()
55{ 65{
56 //--- 66 //---
diff --git a/src/universe.hpp b/src/universe.hpp
index 88a53a1..fac5f50 100644
--- a/src/universe.hpp
+++ b/src/universe.hpp
@@ -27,12 +27,7 @@ class ProtectedAllocator final
27 std::mutex mutex; 27 std::mutex mutex;
28 28
29 [[nodiscard]] 29 [[nodiscard]]
30 static void* protected_lua_Alloc(void* const ud_, void* const ptr_, size_t const osize_, size_t const nsize_) 30 static void* Protected_lua_Alloc(void* const ud_, void* const ptr_, size_t const osize_, size_t const nsize_);
31 {
32 ProtectedAllocator* const allocator{ static_cast<ProtectedAllocator*>(ud_) };
33 std::lock_guard<std::mutex> _guard{ allocator->mutex };
34 return allocator->alloc(ptr_, osize_, nsize_);
35 }
36 31
37 public: 32 public:
38 // we are not like our base class: we can't be created inside a full userdata (or we would have to install a metatable and __gc handler to destroy ourselves properly) 33 // we are not like our base class: we can't be created inside a full userdata (or we would have to install a metatable and __gc handler to destroy ourselves properly)
@@ -42,13 +37,13 @@ class ProtectedAllocator final
42 37
43 AllocatorDefinition makeDefinition() 38 AllocatorDefinition makeDefinition()
44 { 39 {
45 return AllocatorDefinition{ protected_lua_Alloc, this }; 40 return AllocatorDefinition{ Protected_lua_Alloc, this };
46 } 41 }
47 42
48 void installIn(lua_State* const L_) const 43 void installIn(lua_State* const L_) const
49 { 44 {
50 // install our replacement allocator function (this is a C function, we need to deconst ourselves) 45 // install our replacement allocator function (this is a C function, we need to deconst ourselves)
51 lua_setallocf(L_, protected_lua_Alloc, static_cast<void*>(const_cast<ProtectedAllocator*>(this))); 46 lua_setallocf(L_, Protected_lua_Alloc, static_cast<void*>(const_cast<ProtectedAllocator*>(this)));
52 } 47 }
53 48
54 void removeFrom(lua_State* const L_) const 49 void removeFrom(lua_State* const L_) const