aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-06-10 10:59:08 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-06-10 10:59:08 +0200
commite7fa2439c8f328ab146037628bce30894e36a32c (patch)
tree12676776098fc8a737d4917251391d0c37cef906
parent40d6d3f59de802c6e2187540eb654248a5affc30 (diff)
downloadlanes-e7fa2439c8f328ab146037628bce30894e36a32c.tar.gz
lanes-e7fa2439c8f328ab146037628bce30894e36a32c.tar.bz2
lanes-e7fa2439c8f328ab146037628bce30894e36a32c.zip
Unify the value returned by linda:deep() and the string conversion of an unnamed Linda
-rw-r--r--docs/index.html14
-rw-r--r--src/linda.cpp4
-rw-r--r--src/linda.h7
3 files changed, 20 insertions, 5 deletions
diff --git a/docs/index.html b/docs/index.html
index dd7854a..60f4970 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -1213,18 +1213,18 @@
1213<table border="1" bgcolor="#E0E0FF" cellpadding="10" style="width:50%"><tr><td><pre> 1213<table border="1" bgcolor="#E0E0FF" cellpadding="10" style="width:50%"><tr><td><pre>
1214 h = lanes.linda([opt_name, [opt_group]]) 1214 h = lanes.linda([opt_name, [opt_group]])
1215 1215
1216 [true|lanes.cancel_error] = h:send([timeout_secs,] key, ...) 1216 true|lanes.cancel_error = h:send([timeout_secs,] key, ...)
1217 1217
1218 key, val = h:receive([timeout_secs,] key [, key...]) 1218 key, val = h:receive([timeout_secs,] key [, key...])
1219 1219
1220 key, val [, val...] = h:receive(timeout, h.batched, key, n_uint_min[, n_uint_max]) 1220 key, val [, val...] = h:receive(timeout, h.batched, key, n_uint_min[, n_uint_max])
1221 1221
1222 [true|lanes.cancel_error] = h:limit(key, n_uint) 1222 true|lanes.cancel_error = h:limit(key, n_uint)
1223</pre></td></tr></table> 1223</pre></td></tr></table>
1224 1224
1225<p> 1225<p>
1226 Converting the Linda to a string will yield the provided name prefixed by <tt>"Linda: "</tt>.<br/> 1226 Converting the Linda to a string will yield the provided name prefixed by <tt>"Linda: "</tt>.<br/>
1227 If <tt>opt_name</tt> is omitted, it will evaluate to an hexadecimal number uniquely representing that Linda.<br/> 1227 If <tt>opt_name</tt> is omitted, it will evaluate to an hexadecimal number uniquely representing that Linda when the Linda is converted to a string. The value is the same as returned by <tt>linda:deep()</tt>.<br/>
1228 If <tt>opt_name</tt> is <tt>"auto"</tt>, Lanes will try to construct a name from the source location that called <tt>lanes.linda()</tt>. If that fails, the Linda name will be <tt>"&lt;unresolved&gt;"</tt>. 1228 If <tt>opt_name</tt> is <tt>"auto"</tt>, Lanes will try to construct a name from the source location that called <tt>lanes.linda()</tt>. If that fails, the Linda name will be <tt>"&lt;unresolved&gt;"</tt>.
1229</p> 1229</p>
1230<p> 1230<p>
@@ -1331,6 +1331,14 @@
1331 If not void, the lane's cancel status overrides the Linda's cancel status. 1331 If not void, the lane's cancel status overrides the Linda's cancel status.
1332</p> 1332</p>
1333 1333
1334<table border="1" bgcolor="#E0E0FF" cellpadding="10" style="width:50%"><tr><td><pre>
1335 light userdata = h:deep()
1336</pre></td></tr></table>
1337
1338<p>
1339 Returns a light userdata that uniquely represents the Linda. The stored value is the same as what is seen when converting an unnamed Linda to a string.
1340</p>
1341
1334<h3 id="keepers">Granularity of using Lindas</h3> 1342<h3 id="keepers">Granularity of using Lindas</h3>
1335 1343
1336<p> 1344<p>
diff --git a/src/linda.cpp b/src/linda.cpp
index 81926f9..4dc2162 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -87,7 +87,7 @@ template <bool OPT>
87 std::ignore = luaG_pushstring(L_, _lindaName); 87 std::ignore = luaG_pushstring(L_, _lindaName);
88 } else { 88 } else {
89 // obfuscate the pointer so that we can't read the value with our eyes out of a script 89 // obfuscate the pointer so that we can't read the value with our eyes out of a script
90 std::ignore = luaG_pushstring(L_, "%p", std::bit_cast<uintptr_t>(_linda) ^ kConfigRegKey.storage); 90 std::ignore = luaG_pushstring(L_, "%p", _linda->obfuscated());
91 } 91 }
92 lua_concat(L_, 2); 92 lua_concat(L_, 2);
93 return 1; 93 return 1;
@@ -344,7 +344,7 @@ LUAG_FUNC(linda_count)
344LUAG_FUNC(linda_deep) 344LUAG_FUNC(linda_deep)
345{ 345{
346 Linda* const _linda{ ToLinda<false>(L_, 1) }; 346 Linda* const _linda{ ToLinda<false>(L_, 1) };
347 lua_pushlightuserdata(L_, _linda); // just the address 347 lua_pushlightuserdata(L_, _linda->obfuscated<void*>()); // just the address
348 return 1; 348 return 1;
349} 349}
350 350
diff --git a/src/linda.h b/src/linda.h
index 3098161..6901a86 100644
--- a/src/linda.h
+++ b/src/linda.h
@@ -80,6 +80,13 @@ class Linda
80 [[nodiscard]] Keeper* acquireKeeper() const; 80 [[nodiscard]] Keeper* acquireKeeper() const;
81 [[nodiscard]] std::string_view getName() const; 81 [[nodiscard]] std::string_view getName() const;
82 [[nodiscard]] bool inKeeperOperation() const { return keeperOperationCount.load(std::memory_order_seq_cst) != 0; } 82 [[nodiscard]] bool inKeeperOperation() const { return keeperOperationCount.load(std::memory_order_seq_cst) != 0; }
83 template <typename T = uintptr_t>
84 [[nodiscard]] T obfuscated() const
85 {
86 // xxh64 of string "kObfuscator" generated at https://www.pelock.com/products/hash-calculator
87 static constexpr UniqueKey kObfuscator{ 0x7B8AA1F99A3BD782ull };
88 return std::bit_cast<T>(std::bit_cast<uintptr_t>(this) ^ kObfuscator.storage);
89 };
83 void releaseKeeper(Keeper* keeper_) const; 90 void releaseKeeper(Keeper* keeper_) const;
84 [[nodiscard]] static int ProtectedCall(lua_State* L_, lua_CFunction f_); 91 [[nodiscard]] static int ProtectedCall(lua_State* L_, lua_CFunction f_);
85 [[nodiscard]] KeeperOperationInProgress startKeeperOperation(lua_State* const L_) { return KeeperOperationInProgress{ *this, L_ }; }; 92 [[nodiscard]] KeeperOperationInProgress startKeeperOperation(lua_State* const L_) { return KeeperOperationInProgress{ *this, L_ }; };