aboutsummaryrefslogtreecommitdiff
path: root/src/universe.hpp
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-12-17 11:53:15 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2024-12-17 11:53:15 +0100
commit48c99e29ae38db79522fb2833f3144ae58c7a906 (patch)
tree4fbf42918fa22fad025e75733dbe3caf76325f9b /src/universe.hpp
parentefd5318b2d9132996bf35a6af2e82706665890ff (diff)
downloadlanes-48c99e29ae38db79522fb2833f3144ae58c7a906.tar.gz
lanes-48c99e29ae38db79522fb2833f3144ae58c7a906.tar.bz2
lanes-48c99e29ae38db79522fb2833f3144ae58c7a906.zip
Some constitude tweaks
Diffstat (limited to 'src/universe.hpp')
-rw-r--r--src/universe.hpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/universe.hpp b/src/universe.hpp
index dbf0ece..d35172d 100644
--- a/src/universe.hpp
+++ b/src/universe.hpp
@@ -26,7 +26,7 @@ class ProtectedAllocator
26 std::mutex mutex; 26 std::mutex mutex;
27 27
28 [[nodiscard]] 28 [[nodiscard]]
29 static void* protected_lua_Alloc(void* ud_, void* ptr_, size_t osize_, size_t nsize_) 29 static void* protected_lua_Alloc(void* const ud_, void* const ptr_, size_t const osize_, size_t const nsize_)
30 { 30 {
31 ProtectedAllocator* const allocator{ static_cast<ProtectedAllocator*>(ud_) }; 31 ProtectedAllocator* const allocator{ static_cast<ProtectedAllocator*>(ud_) };
32 std::lock_guard<std::mutex> guard{ allocator->mutex }; 32 std::lock_guard<std::mutex> guard{ allocator->mutex };
@@ -36,8 +36,8 @@ class ProtectedAllocator
36 public: 36 public:
37 // 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) 37 // 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)
38 [[nodiscard]] 38 [[nodiscard]]
39 static void* operator new(size_t size_, lua_State* L_) noexcept = delete; 39 static void* operator new(size_t const size_, lua_State* const L_) noexcept = delete;
40 static void operator delete(void* p_, lua_State* L_) = delete; 40 static void operator delete(void* const p_, lua_State* const L_) = delete;
41 41
42 AllocatorDefinition makeDefinition() 42 AllocatorDefinition makeDefinition()
43 { 43 {
@@ -58,6 +58,7 @@ class ProtectedAllocator
58}; 58};
59 59
60// ################################################################################################# 60// #################################################################################################
61// #################################################################################################
61 62
62// xxh64 of string "kUniverseLightRegKey" generated at https://www.pelock.com/products/hash-calculator 63// xxh64 of string "kUniverseLightRegKey" generated at https://www.pelock.com/products/hash-calculator
63static constexpr RegistryUniqueKey kUniverseLightRegKey{ 0x48BBE9CEAB0BA04Full }; 64static constexpr RegistryUniqueKey kUniverseLightRegKey{ 0x48BBE9CEAB0BA04Full };
@@ -127,9 +128,9 @@ class Universe
127 128
128 public: 129 public:
129 [[nodiscard]] 130 [[nodiscard]]
130 static void* operator new([[maybe_unused]] size_t size_, lua_State* L_) noexcept { return luaG_newuserdatauv<Universe>(L_, UserValueCount{ 0 }); }; 131 static void* operator new([[maybe_unused]] size_t const size_, lua_State* const L_) noexcept { return luaG_newuserdatauv<Universe>(L_, UserValueCount{ 0 }); };
131 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception 132 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception
132 static void operator delete([[maybe_unused]] void* p_, [[maybe_unused]] lua_State* L_) {} // nothing to do, as nothing is allocated independently 133 static void operator delete([[maybe_unused]] void* const p_, [[maybe_unused]] lua_State* const L_) {} // nothing to do, as nothing is allocated independently
133 134
134 Universe(); 135 Universe();
135 ~Universe() = default; 136 ~Universe() = default;
@@ -139,15 +140,16 @@ class Universe
139 Universe& operator=(Universe const&) = delete; 140 Universe& operator=(Universe const&) = delete;
140 Universe& operator=(Universe&&) = delete; 141 Universe& operator=(Universe&&) = delete;
141 142
142 void callOnStateCreate(lua_State* const L_, lua_State* const from_, LookupMode const mode_); 143 void callOnStateCreate(lua_State* L_, lua_State* from_, LookupMode mode_);
143 [[nodiscard]] 144 [[nodiscard]]
144 static Universe* Create(lua_State* L_); 145 static Universe* Create(lua_State* L_);
145 [[nodiscard]] 146 [[nodiscard]]
146 static inline Universe* Get(lua_State* L_); 147 static inline Universe* Get(lua_State* L_);
147 void initializeAllocatorFunction(lua_State* L_); 148 void initializeAllocatorFunction(lua_State* L_);
148 static int InitializeFinalizer(lua_State* L_); 149 static int InitializeFinalizer(lua_State* L_);
149 void initializeOnStateCreate(lua_State* const L_); 150 void initializeOnStateCreate(lua_State* L_);
150 lanes::AllocatorDefinition resolveAllocator(lua_State* const L_, std::string_view const& hint_) const; 151 [[nodiscard]]
152 lanes::AllocatorDefinition resolveAllocator(lua_State* L_, std::string_view const& hint_) const;
151 static inline void Store(lua_State* L_, Universe* U_); 153 static inline void Store(lua_State* L_, Universe* U_);
152 [[nodiscard]] 154 [[nodiscard]]
153 bool terminateFreeRunningLanes(lua_Duration shutdownTimeout_, CancelOp op_); 155 bool terminateFreeRunningLanes(lua_Duration shutdownTimeout_, CancelOp op_);
@@ -156,7 +158,7 @@ class Universe
156// ################################################################################################# 158// #################################################################################################
157 159
158[[nodiscard]] 160[[nodiscard]]
159inline Universe* Universe::Get(lua_State* L_) 161inline Universe* Universe::Get(lua_State* const L_)
160{ 162{
161 STACK_CHECK_START_REL(L_, 0); 163 STACK_CHECK_START_REL(L_, 0);
162 Universe* const _universe{ kUniverseLightRegKey.readLightUserDataValue<Universe>(L_) }; 164 Universe* const _universe{ kUniverseLightRegKey.readLightUserDataValue<Universe>(L_) };
@@ -166,7 +168,7 @@ inline Universe* Universe::Get(lua_State* L_)
166 168
167// ################################################################################################# 169// #################################################################################################
168 170
169inline void Universe::Store(lua_State* L_, Universe* U_) 171inline void Universe::Store(lua_State* const L_, Universe* const U_)
170{ 172{
171 // TODO: check if we actually ever call Store with a null universe 173 // TODO: check if we actually ever call Store with a null universe
172 LUA_ASSERT(L_, !U_ || Universe::Get(L_) == nullptr); 174 LUA_ASSERT(L_, !U_ || Universe::Get(L_) == nullptr);