aboutsummaryrefslogtreecommitdiff
path: root/src/universe.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/universe.hpp')
-rw-r--r--src/universe.hpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/universe.hpp b/src/universe.hpp
index 42a3d83..f781e92 100644
--- a/src/universe.hpp
+++ b/src/universe.hpp
@@ -4,6 +4,7 @@
4#include "cancel.hpp" 4#include "cancel.hpp"
5#include "keeper.hpp" 5#include "keeper.hpp"
6#include "lanesconf.h" 6#include "lanesconf.h"
7#include "threading.hpp"
7#include "tracker.hpp" 8#include "tracker.hpp"
8#include "uniquekey.hpp" 9#include "uniquekey.hpp"
9 10
@@ -27,12 +28,7 @@ class ProtectedAllocator final
27 std::mutex mutex; 28 std::mutex mutex;
28 29
29 [[nodiscard]] 30 [[nodiscard]]
30 static void* protected_lua_Alloc(void* const ud_, void* const ptr_, size_t const osize_, size_t const nsize_) 31 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 32
37 public: 33 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) 34 // 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 +38,13 @@ class ProtectedAllocator final
42 38
43 AllocatorDefinition makeDefinition() 39 AllocatorDefinition makeDefinition()
44 { 40 {
45 return AllocatorDefinition{ protected_lua_Alloc, this }; 41 return AllocatorDefinition{ Protected_lua_Alloc, this };
46 } 42 }
47 43
48 void installIn(lua_State* const L_) const 44 void installIn(lua_State* const L_) const
49 { 45 {
50 // install our replacement allocator function (this is a C function, we need to deconst ourselves) 46 // 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))); 47 lua_setallocf(L_, Protected_lua_Alloc, static_cast<void*>(const_cast<ProtectedAllocator*>(this)));
52 } 48 }
53 49
54 void removeFrom(lua_State* const L_) const 50 void removeFrom(lua_State* const L_) const
@@ -75,9 +71,9 @@ class Universe final
75 71
76#ifdef PLATFORM_LINUX 72#ifdef PLATFORM_LINUX
77 // Linux needs to check, whether it's been run as root 73 // Linux needs to check, whether it's been run as root
78 bool const sudo{ geteuid() == 0 }; 74 SudoFlag const sudo{ geteuid() == 0 };
79#else 75#else
80 bool const sudo{ false }; 76 SudoFlag const sudo{ false };
81#endif // PLATFORM_LINUX 77#endif // PLATFORM_LINUX
82 78
83 // for verbose errors 79 // for verbose errors
@@ -99,6 +95,8 @@ class Universe final
99 95
100 Keepers keepers; 96 Keepers keepers;
101 97
98 lua_Duration lindaWakePeriod{};
99
102 // Initialized by 'init_once_LOCKED()': the deep userdata Linda object 100 // Initialized by 'init_once_LOCKED()': the deep userdata Linda object
103 // used for timers (each lane will get a proxy to this) 101 // used for timers (each lane will get a proxy to this)
104 Linda* timerLinda{ nullptr }; 102 Linda* timerLinda{ nullptr };
@@ -130,7 +128,7 @@ class Universe final
130 128
131 public: 129 public:
132 [[nodiscard]] 130 [[nodiscard]]
133 static void* operator new([[maybe_unused]] size_t const size_, lua_State* const 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 luaW_newuserdatauv<Universe>(L_, UserValueCount{ 0 }); };
134 // 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
135 static void operator delete([[maybe_unused]] void* const p_, [[maybe_unused]] lua_State* const 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
136 134