aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cancel.h2
-rw-r--r--src/deep.cpp4
-rw-r--r--src/keeper.cpp2
-rw-r--r--src/keeper.h2
-rw-r--r--src/lanes.cpp10
-rw-r--r--src/lanes_private.h2
-rw-r--r--src/tools.cpp8
-rw-r--r--src/tools.h8
-rw-r--r--src/uniquekey.h91
-rw-r--r--src/universe.cpp4
10 files changed, 74 insertions, 59 deletions
diff --git a/src/cancel.h b/src/cancel.h
index 8cff1c9..a25c078 100644
--- a/src/cancel.h
+++ b/src/cancel.h
@@ -45,7 +45,7 @@ enum class CancelOp
45}; 45};
46 46
47// crc64/we of string "CANCEL_ERROR" generated at http://www.nitrxgen.net/hashgen/ 47// crc64/we of string "CANCEL_ERROR" generated at http://www.nitrxgen.net/hashgen/
48static constexpr UniqueKey CANCEL_ERROR{ 0xe97d41626cc97577ull, "lanes.cancel_error" }; // 'raise_cancel_error' sentinel 48static constexpr UniqueKey CANCEL_ERROR{ 0xE97D41626CC97577ull, "lanes.cancel_error" }; // 'raise_cancel_error' sentinel
49 49
50[[nodiscard]] CancelOp which_cancel_op(char const* op_string_); 50[[nodiscard]] CancelOp which_cancel_op(char const* op_string_);
51[[nodiscard]] CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hook_count_, lua_Duration secs_, bool wake_lindas_); 51[[nodiscard]] CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hook_count_, lua_Duration secs_, bool wake_lindas_);
diff --git a/src/deep.cpp b/src/deep.cpp
index 3326f98..3e1d90a 100644
--- a/src/deep.cpp
+++ b/src/deep.cpp
@@ -54,13 +54,13 @@ THE SOFTWARE.
54* factory -> metatable 54* factory -> metatable
55*/ 55*/
56// crc64/we of string "DEEP_LOOKUP_KEY" generated at http://www.nitrxgen.net/hashgen/ 56// crc64/we of string "DEEP_LOOKUP_KEY" generated at http://www.nitrxgen.net/hashgen/
57static constexpr UniqueKey DEEP_LOOKUP_KEY{ 0x9fb9b4f3f633d83dull }; 57static constexpr RegistryUniqueKey DEEP_LOOKUP_KEY{ 0x9FB9B4F3F633D83Dull };
58 58
59/* 59/*
60 * The deep proxy cache is a weak valued table listing all deep UD proxies indexed by the deep UD that they are proxying 60 * The deep proxy cache is a weak valued table listing all deep UD proxies indexed by the deep UD that they are proxying
61 * crc64/we of string "DEEP_PROXY_CACHE_KEY" generated at http://www.nitrxgen.net/hashgen/ 61 * crc64/we of string "DEEP_PROXY_CACHE_KEY" generated at http://www.nitrxgen.net/hashgen/
62*/ 62*/
63static constexpr UniqueKey DEEP_PROXY_CACHE_KEY{ 0x05773d6fc26be106ull }; 63static constexpr RegistryUniqueKey DEEP_PROXY_CACHE_KEY{ 0x05773D6FC26BE106ull };
64 64
65/* 65/*
66* Sets up [-1]<->[-2] two-way lookups, and ensures the lookup table exists. 66* Sets up [-1]<->[-2] two-way lookups, and ensures the lookup table exists.
diff --git a/src/keeper.cpp b/src/keeper.cpp
index 5d94944..0875b87 100644
--- a/src/keeper.cpp
+++ b/src/keeper.cpp
@@ -182,7 +182,7 @@ static void fifo_pop( lua_State* L, keeper_fifo* fifo_, int count_)
182// in: linda_ud expected at stack slot idx 182// in: linda_ud expected at stack slot idx
183// out: fifos[ud] 183// out: fifos[ud]
184// crc64/we of string "FIFOS_KEY" generated at http://www.nitrxgen.net/hashgen/ 184// crc64/we of string "FIFOS_KEY" generated at http://www.nitrxgen.net/hashgen/
185static constexpr UniqueKey FIFOS_KEY{ 0xdce50bbc351cd465ull }; 185static constexpr RegistryUniqueKey FIFOS_KEY{ 0xDCE50BBC351CD465ull };
186static void push_table(lua_State* L, int idx_) 186static void push_table(lua_State* L, int idx_)
187{ 187{
188 STACK_GROW(L, 5); 188 STACK_GROW(L, 5);
diff --git a/src/keeper.h b/src/keeper.h
index c1ee244..30de3a6 100644
--- a/src/keeper.h
+++ b/src/keeper.h
@@ -34,7 +34,7 @@ struct Keepers
34 34
35static constexpr uintptr_t KEEPER_MAGIC_SHIFT{ 3 }; 35static constexpr uintptr_t KEEPER_MAGIC_SHIFT{ 3 };
36// crc64/we of string "NIL_SENTINEL" generated at http://www.nitrxgen.net/hashgen/ 36// crc64/we of string "NIL_SENTINEL" generated at http://www.nitrxgen.net/hashgen/
37static constexpr UniqueKey NIL_SENTINEL{ 0x7eaafa003a1d11a1ull, "linda.null" }; 37static constexpr UniqueKey NIL_SENTINEL{ 0x7EAAFA003A1D11A1ull, "linda.null" };
38 38
39void init_keepers(Universe* U, lua_State* L); 39void init_keepers(Universe* U, lua_State* L);
40void close_keepers(Universe* U); 40void close_keepers(Universe* U);
diff --git a/src/lanes.cpp b/src/lanes.cpp
index 3aa3365..6b3a9a1 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -219,7 +219,7 @@ static void securize_debug_threadname(lua_State* L, Lane* lane_)
219#if ERROR_FULL_STACK 219#if ERROR_FULL_STACK
220[[nodiscard]] static int lane_error(lua_State* L); 220[[nodiscard]] static int lane_error(lua_State* L);
221// crc64/we of string "STACKTRACE_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 221// crc64/we of string "STACKTRACE_REGKEY" generated at http://www.nitrxgen.net/hashgen/
222static constexpr UniqueKey STACKTRACE_REGKEY{ 0x534af7d3226a429full }; 222static constexpr RegistryUniqueKey STACKTRACE_REGKEY{ 0x534AF7D3226A429Full };
223#endif // ERROR_FULL_STACK 223#endif // ERROR_FULL_STACK
224 224
225/* 225/*
@@ -231,7 +231,7 @@ static constexpr UniqueKey STACKTRACE_REGKEY{ 0x534af7d3226a429full };
231* anyways complicate that approach. 231* anyways complicate that approach.
232*/ 232*/
233// crc64/we of string "FINALIZER_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 233// crc64/we of string "FINALIZER_REGKEY" generated at http://www.nitrxgen.net/hashgen/
234static constexpr UniqueKey FINALIZER_REGKEY{ 0x188fccb8bf348e09ull }; 234static constexpr RegistryUniqueKey FINALIZER_REGKEY{ 0x188FCCB8BF348E09ull };
235 235
236// ################################################################################################# 236// #################################################################################################
237 237
@@ -634,7 +634,7 @@ LUAG_FUNC( set_singlethreaded)
634#if ERROR_FULL_STACK 634#if ERROR_FULL_STACK
635 635
636// crc64/we of string "EXTENDED_STACKTRACE_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 636// crc64/we of string "EXTENDED_STACKTRACE_REGKEY" generated at http://www.nitrxgen.net/hashgen/
637static constexpr UniqueKey EXTENDED_STACKTRACE_REGKEY{ 0x2357c69a7c92c936ull }; // used as registry key 637static constexpr RegistryUniqueKey EXTENDED_STACKTRACE_REGKEY{ 0x2357C69A7C92C936ull }; // used as registry key
638 638
639LUAG_FUNC( set_error_reporting) 639LUAG_FUNC( set_error_reporting)
640{ 640{
@@ -731,7 +731,7 @@ LUAG_FUNC( set_error_reporting)
731LUAG_FUNC(set_debug_threadname) 731LUAG_FUNC(set_debug_threadname)
732{ 732{
733 // fnv164 of string "debug_threadname" generated at https://www.pelock.com/products/hash-calculator 733 // fnv164 of string "debug_threadname" generated at https://www.pelock.com/products/hash-calculator
734 constexpr UniqueKey hidden_regkey{ 0x79C0669AAAE04440ull }; 734 constexpr RegistryUniqueKey hidden_regkey{ 0x79C0669AAAE04440ull };
735 // C s_lane structure is a light userdata upvalue 735 // C s_lane structure is a light userdata upvalue
736 Lane* const lane{ lua_tolightuserdata<Lane>(L, lua_upvalueindex(1)) }; 736 Lane* const lane{ lua_tolightuserdata<Lane>(L, lua_upvalueindex(1)) };
737 luaL_checktype(L, -1, LUA_TSTRING); // "name" 737 luaL_checktype(L, -1, LUA_TSTRING); // "name"
@@ -960,7 +960,7 @@ LUAG_FUNC(register)
960// ################################################################################################# 960// #################################################################################################
961 961
962// crc64/we of string "GCCB_KEY" generated at http://www.nitrxgen.net/hashgen/ 962// crc64/we of string "GCCB_KEY" generated at http://www.nitrxgen.net/hashgen/
963static constexpr UniqueKey GCCB_KEY{ 0xcfb1f046ef074e88ull }; 963static constexpr UniqueKey GCCB_KEY{ 0xCFB1F046EF074E88ull };
964 964
965//--- 965//---
966// lane_ud = lane_new( function 966// lane_ud = lane_new( function
diff --git a/src/lanes_private.h b/src/lanes_private.h
index 5e6160d..807359f 100644
--- a/src/lanes_private.h
+++ b/src/lanes_private.h
@@ -92,7 +92,7 @@ class Lane
92}; 92};
93 93
94// xxh64 of string "LANE_POINTER_REGKEY" generated at https://www.pelock.com/products/hash-calculator 94// xxh64 of string "LANE_POINTER_REGKEY" generated at https://www.pelock.com/products/hash-calculator
95static constexpr UniqueKey LANE_POINTER_REGKEY{ 0xB3022205633743BCull }; // used as registry key 95static constexpr RegistryUniqueKey LANE_POINTER_REGKEY{ 0xB3022205633743BCull }; // used as registry key
96 96
97// To allow free-running threads (longer lifespan than the handle's) 97// To allow free-running threads (longer lifespan than the handle's)
98// 'Lane' are malloc/free'd and the handle only carries a pointer. 98// 'Lane' are malloc/free'd and the handle only carries a pointer.
diff --git a/src/tools.cpp b/src/tools.cpp
index cd25eda..98cbf27 100644
--- a/src/tools.cpp
+++ b/src/tools.cpp
@@ -38,14 +38,14 @@ THE SOFTWARE.
38DEBUGSPEW_CODE(char const* const DebugSpewIndentScope::debugspew_indent = "----+----!----+----!----+----!----+----!----+----!----+----!----+----!----+"); 38DEBUGSPEW_CODE(char const* const DebugSpewIndentScope::debugspew_indent = "----+----!----+----!----+----!----+----!----+----!----+----!----+----!----+");
39 39
40// crc64/we of string "LOOKUPCACHE_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 40// crc64/we of string "LOOKUPCACHE_REGKEY" generated at http://www.nitrxgen.net/hashgen/
41static constexpr UniqueKey LOOKUPCACHE_REGKEY{ 0x837a68dfc6fcb716ull }; 41static constexpr RegistryUniqueKey LOOKUPCACHE_REGKEY{ 0x837A68DFC6FCB716ull };
42 42
43// ################################################################################################# 43// #################################################################################################
44 44
45/* 45/*
46 * Does what the original 'push_registry_subtable' function did, but adds an optional mode argument to it 46 * Does what the original 'push_registry_subtable' function did, but adds an optional mode argument to it
47 */ 47 */
48void push_registry_subtable_mode( lua_State* L, UniqueKey key_, const char* mode_) 48void push_registry_subtable_mode(lua_State* L, RegistryUniqueKey key_, const char* mode_)
49{ 49{
50 STACK_GROW(L, 3); 50 STACK_GROW(L, 3);
51 STACK_CHECK_START_REL(L, 0); 51 STACK_CHECK_START_REL(L, 0);
@@ -81,7 +81,7 @@ void push_registry_subtable_mode( lua_State* L, UniqueKey key_, const char* mode
81 * Push a registry subtable (keyed by unique 'key_') onto the stack. 81 * Push a registry subtable (keyed by unique 'key_') onto the stack.
82 * If the subtable does not exist, it is created and chained. 82 * If the subtable does not exist, it is created and chained.
83 */ 83 */
84void push_registry_subtable( lua_State* L, UniqueKey key_) 84void push_registry_subtable(lua_State* L, RegistryUniqueKey key_)
85{ 85{
86 push_registry_subtable_mode(L, key_, nullptr); 86 push_registry_subtable_mode(L, key_, nullptr);
87} 87}
@@ -534,7 +534,7 @@ void populate_func_lookup_table(lua_State* L, int i_, char const* name_)
534/*---=== Inter-state copying ===---*/ 534/*---=== Inter-state copying ===---*/
535 535
536// crc64/we of string "REG_MTID" generated at http://www.nitrxgen.net/hashgen/ 536// crc64/we of string "REG_MTID" generated at http://www.nitrxgen.net/hashgen/
537static constexpr UniqueKey REG_MTID{ 0x2e68f9b4751584dcull }; 537static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull };
538 538
539/* 539/*
540* Get a unique ID for metatable at [i]. 540* Get a unique ID for metatable at [i].
diff --git a/src/tools.h b/src/tools.h
index ddf5c67..673d6f0 100644
--- a/src/tools.h
+++ b/src/tools.h
@@ -8,8 +8,8 @@ class Universe;
8 8
9// ################################################################################################# 9// #################################################################################################
10 10
11void push_registry_subtable_mode(lua_State* L, UniqueKey key_, const char* mode_); 11void push_registry_subtable_mode(lua_State* L, RegistryUniqueKey key_, const char* mode_);
12void push_registry_subtable(lua_State* L, UniqueKey key_); 12void push_registry_subtable(lua_State* L, RegistryUniqueKey key_);
13 13
14enum class VT 14enum class VT
15{ 15{
@@ -88,7 +88,7 @@ void initialize_allocator_function(Universe* U, lua_State* L);
88// ################################################################################################# 88// #################################################################################################
89 89
90// crc64/we of string "CONFIG_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 90// crc64/we of string "CONFIG_REGKEY" generated at http://www.nitrxgen.net/hashgen/
91static constexpr UniqueKey CONFIG_REGKEY{ 0x31cd24894eae8624ull }; // registry key to access the configuration 91static constexpr RegistryUniqueKey CONFIG_REGKEY{ 0x31CD24894EAE8624ull }; // registry key to access the configuration
92 92
93// crc64/we of string "LOOKUP_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 93// crc64/we of string "LOOKUP_REGKEY" generated at http://www.nitrxgen.net/hashgen/
94static constexpr UniqueKey LOOKUP_REGKEY{ 0x5051ed67ee7b51a1ull }; // registry key to access the lookup database 94static constexpr RegistryUniqueKey LOOKUP_REGKEY{ 0x5051ED67EE7B51A1ull }; // registry key to access the lookup database
diff --git a/src/uniquekey.h b/src/uniquekey.h
index 84553a5..738cb51 100644
--- a/src/uniquekey.h
+++ b/src/uniquekey.h
@@ -5,77 +5,92 @@
5 5
6#include <bit> 6#include <bit>
7 7
8// #################################################################################################
9
8class UniqueKey 10class UniqueKey
9{ 11{
10 private: 12 protected:
11 13
12 uintptr_t m_storage; 14 uintptr_t const m_storage{ 0 };
13 15
14 public: 16 public:
15 17
16 char const* m_debugName{ nullptr }; 18 char const* m_debugName{ nullptr };
17 19
20 // ---------------------------------------------------------------------------------------------
18 constexpr explicit UniqueKey(uint64_t val_, char const* debugName_ = nullptr) 21 constexpr explicit UniqueKey(uint64_t val_, char const* debugName_ = nullptr)
19#if LUAJIT_FLAVOR() == 64 // building against LuaJIT headers for 64 bits, light userdata is restricted to 47 significant bits, because LuaJIT uses the other bits for internal optimizations 22#if LUAJIT_FLAVOR() == 64 // building against LuaJIT headers for 64 bits, light userdata is restricted to 47 significant bits, because LuaJIT uses the other bits for internal optimizations
20 : m_storage{ static_cast<uintptr_t>(val_ & 0x7fffffffffffull) } 23 : m_storage{ static_cast<uintptr_t>(val_ & 0x7FFFFFFFFFFFull) }
21#else // LUAJIT_FLAVOR() 24#else // LUAJIT_FLAVOR()
22 : m_storage{ static_cast<uintptr_t>(val_) } 25 : m_storage{ static_cast<uintptr_t>(val_) }
23#endif // LUAJIT_FLAVOR() 26#endif // LUAJIT_FLAVOR()
24 , m_debugName{ debugName_ } 27 , m_debugName{ debugName_ }
25 { 28 {
26 } 29 }
30 // ---------------------------------------------------------------------------------------------
27 constexpr UniqueKey(UniqueKey const& rhs_) = default; 31 constexpr UniqueKey(UniqueKey const& rhs_) = default;
28 constexpr bool operator!=(UniqueKey const& rhs_) const 32 // ---------------------------------------------------------------------------------------------
33 constexpr std::strong_ordering operator<=>(UniqueKey const& rhs_) const = default;
34 // ---------------------------------------------------------------------------------------------
35 bool equals(lua_State* const L_, int i_) const
29 { 36 {
30 return m_storage != rhs_.m_storage; 37 return lua_touserdata(L_, i_) == std::bit_cast<void*>(m_storage);
31 } 38 }
32 constexpr bool operator==(UniqueKey const& rhs_) const 39 // ---------------------------------------------------------------------------------------------
40 void pushKey(lua_State* const L_) const
33 { 41 {
34 return m_storage == rhs_.m_storage; 42 lua_pushlightuserdata(L_, std::bit_cast<void*>(m_storage));
35 } 43 }
44};
36 45
37 void pushKey(lua_State* const L) const 46// #################################################################################################
38 { 47
39 lua_pushlightuserdata(L, std::bit_cast<void*>(m_storage)); 48class RegistryUniqueKey : public UniqueKey
40 } 49{
41 bool equals(lua_State* const L, int i) const 50 public:
42 { 51
43 return lua_touserdata(L, i) == std::bit_cast<void*>(m_storage); 52 using UniqueKey::UniqueKey;
44 } 53
45 void pushValue(lua_State* const L) const 54 // ---------------------------------------------------------------------------------------------
55 void pushValue(lua_State* const L_) const
46 { 56 {
47 STACK_CHECK_START_REL(L, 0); 57 STACK_CHECK_START_REL(L_, 0);
48 pushKey(L); 58 pushKey(L_);
49 lua_rawget(L, LUA_REGISTRYINDEX); 59 lua_rawget(L_, LUA_REGISTRYINDEX);
50 STACK_CHECK(L, 1); 60 STACK_CHECK(L_, 1);
51 } 61 }
62 // ---------------------------------------------------------------------------------------------
52 template <typename OP> 63 template <typename OP>
53 void setValue(lua_State* L, OP operation_) const 64 void setValue(lua_State* L_, OP operation_) const
54 { 65 {
55 // Note we can't check stack consistency because operation is not always a push (could be insert, replace, whatever) 66 // Note we can't check stack consistency because operation is not always a push (could be insert, replace, whatever)
56 pushKey(L); // ... key 67 pushKey(L_); // ... key
57 operation_(L); // ... key value 68 operation_(L_); // ... key value
58 lua_rawset(L, LUA_REGISTRYINDEX); // ... 69 lua_rawset(L_, LUA_REGISTRYINDEX); // ...
59 } 70 }
71 // ---------------------------------------------------------------------------------------------
60 template <typename T> 72 template <typename T>
61 T* readLightUserDataValue(lua_State* const L) const 73 T* readLightUserDataValue(lua_State* const L_) const
62 { 74 {
63 STACK_GROW(L, 1); 75 STACK_GROW(L_, 1);
64 STACK_CHECK_START_REL(L, 0); 76 STACK_CHECK_START_REL(L_, 0);
65 pushValue(L); 77 pushValue(L_);
66 T* const value{ lua_tolightuserdata<T>(L, -1) }; // lightuserdata/nil 78 T* const value{ lua_tolightuserdata<T>(L_, -1) }; // lightuserdata/nil
67 lua_pop(L, 1); 79 lua_pop(L_, 1);
68 STACK_CHECK(L, 0); 80 STACK_CHECK(L_, 0);
69 return value; 81 return value;
70 } 82 }
71 bool readBoolValue(lua_State* const L) const 83 // ---------------------------------------------------------------------------------------------
84 bool readBoolValue(lua_State* const L_) const
72 { 85 {
73 STACK_GROW(L, 1); 86 STACK_GROW(L_, 1);
74 STACK_CHECK_START_REL(L, 0); 87 STACK_CHECK_START_REL(L_, 0);
75 pushValue(L); 88 pushValue(L_);
76 bool const value{ lua_toboolean(L, -1) ? true : false}; // bool/nil 89 bool const value{ lua_toboolean(L_, -1) ? true : false}; // bool/nil
77 lua_pop(L, 1); 90 lua_pop(L_, 1);
78 STACK_CHECK(L, 0); 91 STACK_CHECK(L_, 0);
79 return value; 92 return value;
80 } 93 }
81}; 94};
95
96// #################################################################################################
diff --git a/src/universe.cpp b/src/universe.cpp
index a02a5e6..112c840 100644
--- a/src/universe.cpp
+++ b/src/universe.cpp
@@ -37,9 +37,9 @@ THE SOFTWARE.
37#include "uniquekey.h" 37#include "uniquekey.h"
38 38
39// xxh64 of string "UNIVERSE_FULL_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 39// xxh64 of string "UNIVERSE_FULL_REGKEY" generated at http://www.nitrxgen.net/hashgen/
40static constexpr UniqueKey UNIVERSE_FULL_REGKEY{ 0x99CA130C09EDC074ull }; 40static constexpr RegistryUniqueKey UNIVERSE_FULL_REGKEY{ 0x99CA130C09EDC074ull };
41// xxh64 of string "UNIVERSE_LIGHT_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 41// xxh64 of string "UNIVERSE_LIGHT_REGKEY" generated at http://www.nitrxgen.net/hashgen/
42static constexpr UniqueKey UNIVERSE_LIGHT_REGKEY{ 0x3663C07C742CEB81ull }; 42static constexpr RegistryUniqueKey UNIVERSE_LIGHT_REGKEY{ 0x3663C07C742CEB81ull };
43 43
44// ################################################################################################# 44// #################################################################################################
45 45