aboutsummaryrefslogtreecommitdiff
path: root/src/universe.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/universe.h')
-rw-r--r--src/universe.h25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/universe.h b/src/universe.h
index 4be6a9a..7624fed 100644
--- a/src/universe.h
+++ b/src/universe.h
@@ -108,8 +108,6 @@ class ProtectedAllocator
108 108
109// ################################################################################################# 109// #################################################################################################
110 110
111// xxh64 of string "kUniverseFullRegKey" generated at https://www.pelock.com/products/hash-calculator
112static constexpr RegistryUniqueKey kUniverseFullRegKey{ 0x1C2D76870DD9DD9Full };
113// xxh64 of string "kUniverseLightRegKey" generated at https://www.pelock.com/products/hash-calculator 111// xxh64 of string "kUniverseLightRegKey" generated at https://www.pelock.com/products/hash-calculator
114static constexpr RegistryUniqueKey kUniverseLightRegKey{ 0x48BBE9CEAB0BA04Full }; 112static constexpr RegistryUniqueKey kUniverseLightRegKey{ 0x48BBE9CEAB0BA04Full };
115 113
@@ -172,6 +170,11 @@ class Universe
172 // The terminal desinit sequence should wait for all such processing to terminate before force-killing threads 170 // The terminal desinit sequence should wait for all such processing to terminate before force-killing threads
173 std::atomic<int> selfdestructingCount{ 0 }; 171 std::atomic<int> selfdestructingCount{ 0 };
174 172
173 public:
174 [[nodiscard]] static void* operator new([[maybe_unused]] size_t size_, lua_State* L_) noexcept { return lua_newuserdatauv<Universe>(L_, 0); };
175 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception
176 static void operator delete([[maybe_unused]] void* p_, [[maybe_unused]] lua_State* L_) {} // nothing to do, as nothing is allocated independently
177
175 Universe(); 178 Universe();
176 ~Universe() = default; 179 ~Universe() = default;
177 // non-copyable, non-movable 180 // non-copyable, non-movable
@@ -181,21 +184,18 @@ class Universe
181 Universe& operator=(Universe&&) = delete; 184 Universe& operator=(Universe&&) = delete;
182 185
183 void closeKeepers(); 186 void closeKeepers();
187 [[nodiscard]] static Universe* Create(lua_State* L_);
188 [[nodiscard]] static inline Universe* Get(lua_State* L_);
184 void initializeAllocatorFunction(lua_State* L_); 189 void initializeAllocatorFunction(lua_State* L_);
185 static int InitializeFinalizer(lua_State* L_); 190 static int InitializeFinalizer(lua_State* L_);
186 void initializeKeepers(lua_State* L_); 191 void initializeKeepers(lua_State* L_);
192 static inline void Store(lua_State* L_, Universe* U_);
187 void terminateFreeRunningLanes(lua_State* L_, lua_Duration shutdownTimeout_, CancelOp op_); 193 void terminateFreeRunningLanes(lua_State* L_, lua_Duration shutdownTimeout_, CancelOp op_);
188}; 194};
189 195
190// ################################################################################################# 196// #################################################################################################
191 197
192[[nodiscard]] Universe* universe_get(lua_State* L_); 198inline Universe* Universe::Get(lua_State* L_)
193[[nodiscard]] Universe* universe_create(lua_State* L_);
194void universe_store(lua_State* L_, Universe* U_);
195
196// #################################################################################################
197
198[[nodiscard]] inline Universe* universe_get(lua_State* L_)
199{ 199{
200 STACK_CHECK_START_REL(L_, 0); 200 STACK_CHECK_START_REL(L_, 0);
201 Universe* const _universe{ kUniverseLightRegKey.readLightUserDataValue<Universe>(L_) }; 201 Universe* const _universe{ kUniverseLightRegKey.readLightUserDataValue<Universe>(L_) };
@@ -205,9 +205,10 @@ void universe_store(lua_State* L_, Universe* U_);
205 205
206// ################################################################################################# 206// #################################################################################################
207 207
208inline void universe_store(lua_State* L_, Universe* U_) 208inline void Universe::Store(lua_State* L_, Universe* U_)
209{ 209{
210 LUA_ASSERT(L_, !U_ || universe_get(L_) == nullptr); 210 // TODO: check if we actually ever call Store with a null universe
211 LUA_ASSERT(L_, !U_ || Universe::Get(L_) == nullptr);
211 STACK_CHECK_START_REL(L_, 0); 212 STACK_CHECK_START_REL(L_, 0);
212 kUniverseLightRegKey.setValue(L_, [U = U_](lua_State* L_) { U ? lua_pushlightuserdata(L_, U) : lua_pushnil(L_); }); 213 kUniverseLightRegKey.setValue(L_, [U = U_](lua_State* L_) { U ? lua_pushlightuserdata(L_, U) : lua_pushnil(L_); });
213 STACK_CHECK(L_, 0); 214 STACK_CHECK(L_, 0);
@@ -215,4 +216,4 @@ inline void universe_store(lua_State* L_, Universe* U_)
215 216
216// ################################################################################################# 217// #################################################################################################
217 218
218int universe_gc(lua_State* L_); 219LUAG_FUNC(universe_gc);