diff options
Diffstat (limited to 'src/universe.hpp')
-rw-r--r-- | src/universe.hpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/universe.hpp b/src/universe.hpp index 77fbb52..fa1e238 100644 --- a/src/universe.hpp +++ b/src/universe.hpp | |||
@@ -25,7 +25,8 @@ class ProtectedAllocator | |||
25 | 25 | ||
26 | std::mutex mutex; | 26 | std::mutex mutex; |
27 | 27 | ||
28 | [[nodiscard]] static void* protected_lua_Alloc(void* ud_, void* ptr_, size_t osize_, size_t nsize_) | 28 | [[nodiscard]] |
29 | static void* protected_lua_Alloc(void* ud_, void* ptr_, size_t osize_, size_t nsize_) | ||
29 | { | 30 | { |
30 | ProtectedAllocator* const allocator{ static_cast<ProtectedAllocator*>(ud_) }; | 31 | ProtectedAllocator* const allocator{ static_cast<ProtectedAllocator*>(ud_) }; |
31 | std::lock_guard<std::mutex> guard{ allocator->mutex }; | 32 | std::lock_guard<std::mutex> guard{ allocator->mutex }; |
@@ -34,7 +35,8 @@ class ProtectedAllocator | |||
34 | 35 | ||
35 | public: | 36 | public: |
36 | // 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) |
37 | [[nodiscard]] static void* operator new(size_t size_, lua_State* L_) noexcept = delete; | 38 | [[nodiscard]] |
39 | static void* operator new(size_t size_, lua_State* L_) noexcept = delete; | ||
38 | static void operator delete(void* p_, lua_State* L_) = delete; | 40 | static void operator delete(void* p_, lua_State* L_) = delete; |
39 | 41 | ||
40 | AllocatorDefinition makeDefinition() | 42 | AllocatorDefinition makeDefinition() |
@@ -121,7 +123,8 @@ class Universe | |||
121 | std::atomic<int> selfdestructingCount{ 0 }; | 123 | std::atomic<int> selfdestructingCount{ 0 }; |
122 | 124 | ||
123 | public: | 125 | public: |
124 | [[nodiscard]] static void* operator new([[maybe_unused]] size_t size_, lua_State* L_) noexcept { return luaG_newuserdatauv<Universe>(L_, UserValueCount{ 0 }); }; | 126 | [[nodiscard]] |
127 | static void* operator new([[maybe_unused]] size_t size_, lua_State* L_) noexcept { return luaG_newuserdatauv<Universe>(L_, UserValueCount{ 0 }); }; | ||
125 | // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception | 128 | // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception |
126 | static void operator delete([[maybe_unused]] void* p_, [[maybe_unused]] lua_State* L_) {} // nothing to do, as nothing is allocated independently | 129 | static void operator delete([[maybe_unused]] void* p_, [[maybe_unused]] lua_State* L_) {} // nothing to do, as nothing is allocated independently |
127 | 130 | ||
@@ -134,18 +137,22 @@ class Universe | |||
134 | Universe& operator=(Universe&&) = delete; | 137 | Universe& operator=(Universe&&) = delete; |
135 | 138 | ||
136 | void callOnStateCreate(lua_State* const L_, lua_State* const from_, LookupMode const mode_); | 139 | void callOnStateCreate(lua_State* const L_, lua_State* const from_, LookupMode const mode_); |
137 | [[nodiscard]] static Universe* Create(lua_State* L_); | 140 | [[nodiscard]] |
138 | [[nodiscard]] static inline Universe* Get(lua_State* L_); | 141 | static Universe* Create(lua_State* L_); |
142 | [[nodiscard]] | ||
143 | static inline Universe* Get(lua_State* L_); | ||
139 | void initializeAllocatorFunction(lua_State* L_); | 144 | void initializeAllocatorFunction(lua_State* L_); |
140 | static int InitializeFinalizer(lua_State* L_); | 145 | static int InitializeFinalizer(lua_State* L_); |
141 | void initializeOnStateCreate(lua_State* const L_); | 146 | void initializeOnStateCreate(lua_State* const L_); |
142 | lanes::AllocatorDefinition resolveAllocator(lua_State* const L_, std::string_view const& hint_) const; | 147 | lanes::AllocatorDefinition resolveAllocator(lua_State* const L_, std::string_view const& hint_) const; |
143 | static inline void Store(lua_State* L_, Universe* U_); | 148 | static inline void Store(lua_State* L_, Universe* U_); |
144 | [[nodiscard]] bool terminateFreeRunningLanes(lua_Duration shutdownTimeout_, CancelOp op_); | 149 | [[nodiscard]] |
150 | bool terminateFreeRunningLanes(lua_Duration shutdownTimeout_, CancelOp op_); | ||
145 | }; | 151 | }; |
146 | 152 | ||
147 | // ################################################################################################# | 153 | // ################################################################################################# |
148 | 154 | ||
155 | [[nodiscard]] | ||
149 | inline Universe* Universe::Get(lua_State* L_) | 156 | inline Universe* Universe::Get(lua_State* L_) |
150 | { | 157 | { |
151 | STACK_CHECK_START_REL(L_, 0); | 158 | STACK_CHECK_START_REL(L_, 0); |