From f73702bcf4372a149b8b01a512c0e086b1e679e2 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Thu, 22 May 2025 18:16:39 +0200 Subject: Minor code cosmetic changes --- src/keeper.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/keeper.cpp') 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 // ################################################################################################# +[[nodiscard]] bool KeyUD::changeLimit(LindaLimit const limit_) { bool const _newSlackAvailable{ @@ -127,6 +128,7 @@ LindaRestrict KeyUD::changeRestrict(LindaRestrict const restrict_) // in: nothing // out: { first = 1, count = 0, limit = -1} +[[nodiscard]] KeyUD* KeyUD::Create(KeeperState const K_) { STACK_GROW(K_, 2); @@ -141,6 +143,7 @@ KeyUD* KeyUD::Create(KeeperState const K_) // ################################################################################################# +[[nodiscard]] KeyUD* KeyUD::GetPtr(KeeperState const K_, StackIndex const idx_) { return luaG_tofulluserdata(K_, idx_); @@ -181,6 +184,7 @@ void KeyUD::peek(KeeperState const K_, int const count_) const // in: fifo // out: remove the fifo table from the stack, push as many items as required on the stack (function assumes they exist in sufficient number) +[[nodiscard]] int KeyUD::pop(KeeperState const K_, int const minCount_, int const maxCount_) { if (count < minCount_) { @@ -243,6 +247,7 @@ void KeyUD::prepareAccess(KeeperState const K_, StackIndex const idx_) const // in: expect this val... on top of the stack // out: nothing, removes all pushed values from the stack +[[nodiscard]] bool KeyUD::push(KeeperState const K_, int const count_, bool const enforceLimit_) { StackIndex const _fifoIdx{ luaG_absindex(K_, StackIndex{ -1 - count_ }) }; @@ -272,7 +277,7 @@ void KeyUD::pushFillStatus(KeeperState const K_) const luaG_pushstring(K_, kUnder); return; } - int const _delta{limit - count}; + int const _delta{ limit - count }; if (_delta < 0) { luaG_pushstring(K_, kOver); } else if (_delta > 0) { @@ -295,7 +300,10 @@ void KeyUD::PushFillStatus(KeeperState const K_, KeyUD const* const key_) // ################################################################################################# -// expects 'this' on top of the stack +// in: expects 'this' on top of the stack +// out: nothing +// returns true if the channel was full +[[nodiscard]] bool KeyUD::reset(KeeperState const K_) { LUA_ASSERT(K_, KeyUD::GetPtr(K_, kIdxTop) == this); @@ -347,6 +355,7 @@ static void PushKeysDB(KeeperState const K_, StackIndex const idx_) // in: linda // out: nothing +[[nodiscard]] int keepercall_collectgarbage(lua_State* const L_) { lua_gc(L_, LUA_GCCOLLECT, 0); @@ -356,6 +365,7 @@ int keepercall_collectgarbage(lua_State* const L_) // ################################################################################################# // in: linda [, key [, ...]] +[[nodiscard]] int keepercall_count(lua_State* const L_) { KeeperState const _K{ L_ }; @@ -419,6 +429,7 @@ int keepercall_count(lua_State* const L_) // in: linda // not part of the linda public API, only used for cleanup at linda GC +[[nodiscard]] int keepercall_destruct(lua_State* const L_) { STACK_GROW(L_, 3); @@ -437,6 +448,7 @@ int keepercall_destruct(lua_State* const L_) // in: linda_ud key [count] // out: N |kRestrictedChannel +[[nodiscard]] int keepercall_get(lua_State* const L_) { KeeperState const _K{ L_ }; @@ -471,6 +483,7 @@ int keepercall_get(lua_State* const L_) // in: linda key [n|nil] // out: boolean, +[[nodiscard]] int keepercall_limit(lua_State* const L_) { KeeperState const _K{ L_ }; @@ -514,6 +527,7 @@ int keepercall_limit(lua_State* const L_) // in: linda, key [, key]? // out: (key, val) or nothing +[[nodiscard]] int keepercall_receive(lua_State* const L_) { KeeperState const _K{ L_ }; @@ -558,6 +572,7 @@ int keepercall_receive(lua_State* const L_) // ################################################################################################# // in: linda key mincount [maxcount] +[[nodiscard]] int keepercall_receive_batched(lua_State* const L_) { KeeperState const _K{ L_ }; @@ -591,6 +606,7 @@ int keepercall_receive_batched(lua_State* const L_) // in: linda key [mode] // out: mode +[[nodiscard]] int keepercall_restrict(lua_State* const L_) { KeeperState const _K{ L_ }; @@ -655,6 +671,7 @@ int keepercall_restrict(lua_State* const L_) // in: linda, key, ... // out: true|false|kRestrictedChannel +[[nodiscard]] int keepercall_send(lua_State* const L_) { KeeperState const _K{ L_ }; @@ -694,6 +711,7 @@ int keepercall_send(lua_State* const L_) // in: linda key [val...] // out: true if the linda was full but it's no longer the case, else false, or kRestrictedChannel if the key is restricted +[[nodiscard]] int keepercall_set(lua_State* const L_) { KeeperState const _K{ L_ }; @@ -763,6 +781,7 @@ int keepercall_set(lua_State* const L_) * * Returns: number of return values (pushed to 'L'), unset in case of error */ +[[nodiscard]] KeeperCallResult keeper_call(KeeperState const K_, keeper_api_t const func_, lua_State* const L_, Linda* const linda_, StackIndex const starting_index_) { KeeperCallResult _result; @@ -832,6 +851,7 @@ KeeperCallResult keeper_call(KeeperState const K_, keeper_api_t const func_, lua // } // ... // } +[[nodiscard]] int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) { Keeper* const _keeper{ linda_.whichKeeper() }; @@ -961,7 +981,7 @@ void Keepers::collectGarbage() // ################################################################################################# - +[[nodiscard]] bool Keepers::close() { if (isClosing.test_and_set(std::memory_order_release)) { -- cgit v1.2.3-55-g6feb