aboutsummaryrefslogtreecommitdiff
path: root/src/universe.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/universe.h')
-rw-r--r--src/universe.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/universe.h b/src/universe.h
index b2107af..58ddffc 100644
--- a/src/universe.h
+++ b/src/universe.h
@@ -11,12 +11,14 @@ extern "C"
11 11
12#include "compat.h" 12#include "compat.h"
13#include "macros_and_utils.h" 13#include "macros_and_utils.h"
14#include "uniquekey.h"
14 15
15#include <mutex> 16#include <mutex>
16 17
17// ################################################################################################# 18// #################################################################################################
18 19
19// forwards 20// forwards
21enum class CancelOp;
20struct DeepPrelude; 22struct DeepPrelude;
21struct Keepers; 23struct Keepers;
22class Lane; 24class Lane;
@@ -114,6 +116,13 @@ class ProtectedAllocator
114 116
115// ################################################################################################# 117// #################################################################################################
116 118
119// xxh64 of string "kUniverseFullRegKey" generated at https://www.pelock.com/products/hash-calculator
120static constexpr RegistryUniqueKey kUniverseFullRegKey{ 0x1C2D76870DD9DD9Full };
121// xxh64 of string "kUniverseLightRegKey" generated at https://www.pelock.com/products/hash-calculator
122static constexpr RegistryUniqueKey kUniverseLightRegKey{ 0x48BBE9CEAB0BA04Full };
123
124// #################################################################################################
125
117// everything regarding the Lanes universe is stored in that global structure 126// everything regarding the Lanes universe is stored in that global structure
118// held as a full userdata in the master Lua state that required it for the first time 127// held as a full userdata in the master Lua state that required it for the first time
119class Universe 128class Universe
@@ -154,6 +163,7 @@ class Universe
154 Lane* volatile trackingFirst{ nullptr }; // will change to TRACKING_END if we want to activate tracking 163 Lane* volatile trackingFirst{ nullptr }; // will change to TRACKING_END if we want to activate tracking
155#endif // HAVE_LANE_TRACKING() 164#endif // HAVE_LANE_TRACKING()
156 165
166 // Protects modifying the selfdestruct chain
157 std::mutex selfdestructMutex; 167 std::mutex selfdestructMutex;
158 168
159 // require() serialization 169 // require() serialization
@@ -178,6 +188,8 @@ class Universe
178 Universe(Universe&&) = delete; 188 Universe(Universe&&) = delete;
179 Universe& operator=(Universe const&) = delete; 189 Universe& operator=(Universe const&) = delete;
180 Universe& operator=(Universe&&) = delete; 190 Universe& operator=(Universe&&) = delete;
191
192 void terminateFreeRunningLanes(lua_State* L_, lua_Duration shutdownTimeout_, CancelOp op_);
181}; 193};
182 194
183// ################################################################################################# 195// #################################################################################################
@@ -211,3 +223,27 @@ class DebugSpewIndentScope
211 } 223 }
212}; 224};
213#endif // USE_DEBUG_SPEW() 225#endif // USE_DEBUG_SPEW()
226
227// #################################################################################################
228
229[[nodiscard]] inline Universe* universe_get(lua_State* L_)
230{
231 STACK_CHECK_START_REL(L_, 0);
232 Universe* const universe{ kUniverseLightRegKey.readLightUserDataValue<Universe>(L_) };
233 STACK_CHECK(L_, 0);
234 return universe;
235}
236
237// #################################################################################################
238
239inline void universe_store(lua_State* L_, Universe* U_)
240{
241 LUA_ASSERT(L_, !U_ || universe_get(L_) == nullptr);
242 STACK_CHECK_START_REL(L_, 0);
243 kUniverseLightRegKey.setValue(L_, [U = U_](lua_State* L_) { U ? lua_pushlightuserdata(L_, U) : lua_pushnil(L_); });
244 STACK_CHECK(L_, 0);
245}
246
247// #################################################################################################
248
249int universe_gc(lua_State* L_);