aboutsummaryrefslogtreecommitdiff
path: root/src/keeper.cpp
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2025-05-22 18:16:39 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2025-05-22 18:16:39 +0200
commitf73702bcf4372a149b8b01a512c0e086b1e679e2 (patch)
tree2adb57140e899f6f20b210e1f1ea56209f23c4a0 /src/keeper.cpp
parentedf519ce0cb247260fc8abda2e1ca9dcd517e3e4 (diff)
downloadlanes-f73702bcf4372a149b8b01a512c0e086b1e679e2.tar.gz
lanes-f73702bcf4372a149b8b01a512c0e086b1e679e2.tar.bz2
lanes-f73702bcf4372a149b8b01a512c0e086b1e679e2.zip
Minor code cosmetic changes
Diffstat (limited to 'src/keeper.cpp')
-rw-r--r--src/keeper.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/keeper.cpp b/src/keeper.cpp
index 7619eb4..2e13de3 100644
--- a/src/keeper.cpp
+++ b/src/keeper.cpp
@@ -104,6 +104,7 @@ class KeyUD final
104 104
105// ################################################################################################# 105// #################################################################################################
106 106
107[[nodiscard]]
107bool KeyUD::changeLimit(LindaLimit const limit_) 108bool KeyUD::changeLimit(LindaLimit const limit_)
108{ 109{
109 bool const _newSlackAvailable{ 110 bool const _newSlackAvailable{
@@ -127,6 +128,7 @@ LindaRestrict KeyUD::changeRestrict(LindaRestrict const restrict_)
127 128
128// in: nothing 129// in: nothing
129// out: { first = 1, count = 0, limit = -1} 130// out: { first = 1, count = 0, limit = -1}
131[[nodiscard]]
130KeyUD* KeyUD::Create(KeeperState const K_) 132KeyUD* KeyUD::Create(KeeperState const K_)
131{ 133{
132 STACK_GROW(K_, 2); 134 STACK_GROW(K_, 2);
@@ -141,6 +143,7 @@ KeyUD* KeyUD::Create(KeeperState const K_)
141 143
142// ################################################################################################# 144// #################################################################################################
143 145
146[[nodiscard]]
144KeyUD* KeyUD::GetPtr(KeeperState const K_, StackIndex const idx_) 147KeyUD* KeyUD::GetPtr(KeeperState const K_, StackIndex const idx_)
145{ 148{
146 return luaG_tofulluserdata<KeyUD>(K_, idx_); 149 return luaG_tofulluserdata<KeyUD>(K_, idx_);
@@ -181,6 +184,7 @@ void KeyUD::peek(KeeperState const K_, int const count_) const
181 184
182// in: fifo 185// in: fifo
183// out: remove the fifo table from the stack, push as many items as required on the stack (function assumes they exist in sufficient number) 186// out: remove the fifo table from the stack, push as many items as required on the stack (function assumes they exist in sufficient number)
187[[nodiscard]]
184int KeyUD::pop(KeeperState const K_, int const minCount_, int const maxCount_) 188int KeyUD::pop(KeeperState const K_, int const minCount_, int const maxCount_)
185{ 189{
186 if (count < minCount_) { 190 if (count < minCount_) {
@@ -243,6 +247,7 @@ void KeyUD::prepareAccess(KeeperState const K_, StackIndex const idx_) const
243 247
244// in: expect this val... on top of the stack 248// in: expect this val... on top of the stack
245// out: nothing, removes all pushed values from the stack 249// out: nothing, removes all pushed values from the stack
250[[nodiscard]]
246bool KeyUD::push(KeeperState const K_, int const count_, bool const enforceLimit_) 251bool KeyUD::push(KeeperState const K_, int const count_, bool const enforceLimit_)
247{ 252{
248 StackIndex const _fifoIdx{ luaG_absindex(K_, StackIndex{ -1 - count_ }) }; 253 StackIndex const _fifoIdx{ luaG_absindex(K_, StackIndex{ -1 - count_ }) };
@@ -272,7 +277,7 @@ void KeyUD::pushFillStatus(KeeperState const K_) const
272 luaG_pushstring(K_, kUnder); 277 luaG_pushstring(K_, kUnder);
273 return; 278 return;
274 } 279 }
275 int const _delta{limit - count}; 280 int const _delta{ limit - count };
276 if (_delta < 0) { 281 if (_delta < 0) {
277 luaG_pushstring(K_, kOver); 282 luaG_pushstring(K_, kOver);
278 } else if (_delta > 0) { 283 } else if (_delta > 0) {
@@ -295,7 +300,10 @@ void KeyUD::PushFillStatus(KeeperState const K_, KeyUD const* const key_)
295 300
296// ################################################################################################# 301// #################################################################################################
297 302
298// expects 'this' on top of the stack 303// in: expects 'this' on top of the stack
304// out: nothing
305// returns true if the channel was full
306[[nodiscard]]
299bool KeyUD::reset(KeeperState const K_) 307bool KeyUD::reset(KeeperState const K_)
300{ 308{
301 LUA_ASSERT(K_, KeyUD::GetPtr(K_, kIdxTop) == this); 309 LUA_ASSERT(K_, KeyUD::GetPtr(K_, kIdxTop) == this);
@@ -347,6 +355,7 @@ static void PushKeysDB(KeeperState const K_, StackIndex const idx_)
347 355
348// in: linda 356// in: linda
349// out: nothing 357// out: nothing
358[[nodiscard]]
350int keepercall_collectgarbage(lua_State* const L_) 359int keepercall_collectgarbage(lua_State* const L_)
351{ 360{
352 lua_gc(L_, LUA_GCCOLLECT, 0); 361 lua_gc(L_, LUA_GCCOLLECT, 0);
@@ -356,6 +365,7 @@ int keepercall_collectgarbage(lua_State* const L_)
356// ################################################################################################# 365// #################################################################################################
357 366
358// in: linda [, key [, ...]] 367// in: linda [, key [, ...]]
368[[nodiscard]]
359int keepercall_count(lua_State* const L_) 369int keepercall_count(lua_State* const L_)
360{ 370{
361 KeeperState const _K{ L_ }; 371 KeeperState const _K{ L_ };
@@ -419,6 +429,7 @@ int keepercall_count(lua_State* const L_)
419 429
420// in: linda 430// in: linda
421// not part of the linda public API, only used for cleanup at linda GC 431// not part of the linda public API, only used for cleanup at linda GC
432[[nodiscard]]
422int keepercall_destruct(lua_State* const L_) 433int keepercall_destruct(lua_State* const L_)
423{ 434{
424 STACK_GROW(L_, 3); 435 STACK_GROW(L_, 3);
@@ -437,6 +448,7 @@ int keepercall_destruct(lua_State* const L_)
437 448
438// in: linda_ud key [count] 449// in: linda_ud key [count]
439// out: N <N values>|kRestrictedChannel 450// out: N <N values>|kRestrictedChannel
451[[nodiscard]]
440int keepercall_get(lua_State* const L_) 452int keepercall_get(lua_State* const L_)
441{ 453{
442 KeeperState const _K{ L_ }; 454 KeeperState const _K{ L_ };
@@ -471,6 +483,7 @@ int keepercall_get(lua_State* const L_)
471 483
472// in: linda key [n|nil] 484// in: linda key [n|nil]
473// out: boolean, <fill status: string> 485// out: boolean, <fill status: string>
486[[nodiscard]]
474int keepercall_limit(lua_State* const L_) 487int keepercall_limit(lua_State* const L_)
475{ 488{
476 KeeperState const _K{ L_ }; 489 KeeperState const _K{ L_ };
@@ -514,6 +527,7 @@ int keepercall_limit(lua_State* const L_)
514 527
515// in: linda, key [, key]? 528// in: linda, key [, key]?
516// out: (key, val) or nothing 529// out: (key, val) or nothing
530[[nodiscard]]
517int keepercall_receive(lua_State* const L_) 531int keepercall_receive(lua_State* const L_)
518{ 532{
519 KeeperState const _K{ L_ }; 533 KeeperState const _K{ L_ };
@@ -558,6 +572,7 @@ int keepercall_receive(lua_State* const L_)
558// ################################################################################################# 572// #################################################################################################
559 573
560// in: linda key mincount [maxcount] 574// in: linda key mincount [maxcount]
575[[nodiscard]]
561int keepercall_receive_batched(lua_State* const L_) 576int keepercall_receive_batched(lua_State* const L_)
562{ 577{
563 KeeperState const _K{ L_ }; 578 KeeperState const _K{ L_ };
@@ -591,6 +606,7 @@ int keepercall_receive_batched(lua_State* const L_)
591 606
592// in: linda key [mode] 607// in: linda key [mode]
593// out: mode 608// out: mode
609[[nodiscard]]
594int keepercall_restrict(lua_State* const L_) 610int keepercall_restrict(lua_State* const L_)
595{ 611{
596 KeeperState const _K{ L_ }; 612 KeeperState const _K{ L_ };
@@ -655,6 +671,7 @@ int keepercall_restrict(lua_State* const L_)
655 671
656// in: linda, key, ... 672// in: linda, key, ...
657// out: true|false|kRestrictedChannel 673// out: true|false|kRestrictedChannel
674[[nodiscard]]
658int keepercall_send(lua_State* const L_) 675int keepercall_send(lua_State* const L_)
659{ 676{
660 KeeperState const _K{ L_ }; 677 KeeperState const _K{ L_ };
@@ -694,6 +711,7 @@ int keepercall_send(lua_State* const L_)
694 711
695// in: linda key [val...] 712// in: linda key [val...]
696// out: true if the linda was full but it's no longer the case, else false, or kRestrictedChannel if the key is restricted 713// out: true if the linda was full but it's no longer the case, else false, or kRestrictedChannel if the key is restricted
714[[nodiscard]]
697int keepercall_set(lua_State* const L_) 715int keepercall_set(lua_State* const L_)
698{ 716{
699 KeeperState const _K{ L_ }; 717 KeeperState const _K{ L_ };
@@ -763,6 +781,7 @@ int keepercall_set(lua_State* const L_)
763 * 781 *
764 * Returns: number of return values (pushed to 'L'), unset in case of error 782 * Returns: number of return values (pushed to 'L'), unset in case of error
765 */ 783 */
784[[nodiscard]]
766KeeperCallResult keeper_call(KeeperState const K_, keeper_api_t const func_, lua_State* const L_, Linda* const linda_, StackIndex const starting_index_) 785KeeperCallResult keeper_call(KeeperState const K_, keeper_api_t const func_, lua_State* const L_, Linda* const linda_, StackIndex const starting_index_)
767{ 786{
768 KeeperCallResult _result; 787 KeeperCallResult _result;
@@ -832,6 +851,7 @@ KeeperCallResult keeper_call(KeeperState const K_, keeper_api_t const func_, lua
832// } 851// }
833// ... 852// ...
834// } 853// }
854[[nodiscard]]
835int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) 855int Keeper::PushLindaStorage(Linda& linda_, DestState const L_)
836{ 856{
837 Keeper* const _keeper{ linda_.whichKeeper() }; 857 Keeper* const _keeper{ linda_.whichKeeper() };
@@ -961,7 +981,7 @@ void Keepers::collectGarbage()
961 981
962// ################################################################################################# 982// #################################################################################################
963 983
964 984[[nodiscard]]
965bool Keepers::close() 985bool Keepers::close()
966{ 986{
967 if (isClosing.test_and_set(std::memory_order_release)) { 987 if (isClosing.test_and_set(std::memory_order_release)) {