aboutsummaryrefslogtreecommitdiff
path: root/src/linda.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/linda.cpp')
-rw-r--r--src/linda.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/linda.cpp b/src/linda.cpp
index f4dd7e7..13627aa 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -477,22 +477,24 @@ LUAG_FUNC(linda_limit)
477 477
478 KeeperCallResult _pushed; 478 KeeperCallResult _pushed;
479 if (_linda->cancelRequest == CancelRequest::None) { 479 if (_linda->cancelRequest == CancelRequest::None) {
480 Keeper* const _keeper{ _linda->whichKeeper() };
481 if (_unlimited) { 480 if (_unlimited) {
482 LUA_ASSERT(L_, lua_gettop(L_) == 3 && luaG_tostring(L_, 3) == "unlimited"); 481 LUA_ASSERT(L_, lua_gettop(L_) == 3 && luaG_tostring(L_, 3) == "unlimited");
483 // inside the Keeper, unlimited is signified with a -1 limit (can't use nil because of nil kNilSentinel conversions!) 482 // inside the Keeper, unlimited is signified with a -1 limit (can't use nil because of nil kNilSentinel conversions!)
484 lua_pop(L_, 1); // L_: linda key 483 lua_pop(L_, 1); // L_: linda key
485 lua_pushinteger(L_, -1); // L_: linda key nil 484 lua_pushinteger(L_, -1); // L_: linda key nil
486 } 485 }
486 Keeper* const _keeper{ _linda->whichKeeper() };
487 _pushed = keeper_call(_keeper->K, KEEPER_API(limit), L_, _linda, 2); 487 _pushed = keeper_call(_keeper->K, KEEPER_API(limit), L_, _linda, 2);
488 LUA_ASSERT(L_, _pushed.has_value() && (_pushed.value() == 1)); 488 LUA_ASSERT(L_, _pushed.has_value() && (_pushed.value() == 2) && luaG_type(L_, -1) == LuaType::STRING);
489 if (_nargs == 3) { // 3 args: setting the limit 489 if (_nargs == 3) { // 3 args: setting the limit
490 LUA_ASSERT(L_, luaG_type(L_, -1) == LuaType::BOOLEAN); // changing the limit: no error, boolean value saying if we should wake blocked writer threads 490 // changing the limit: no error, boolean value saying if we should wake blocked writer threads
491 if (lua_toboolean(L_, -1)) { 491 LUA_ASSERT(L_, luaG_type(L_, -2) == LuaType::BOOLEAN); // L_: bool string
492 if (lua_toboolean(L_, -2)) {
492 _linda->readHappened.notify_all(); // To be done from within the 'K' locking area 493 _linda->readHappened.notify_all(); // To be done from within the 'K' locking area
493 } 494 }
494 } else { // 2 args: reading the limit 495 } else { // 2 args: reading the limit
495 LUA_ASSERT(L_, luaG_type(L_, -1) == LuaType::NUMBER || luaG_tostring(L_, -1) == "unlimited"); // reading the limit: a number >=0 or "unlimited" 496 // reading the limit: a number >=0 or "unlimited"
497 LUA_ASSERT(L_, luaG_type(L_, -2) == LuaType::NUMBER || luaG_tostring(L_, -2) == "unlimited");
496 } 498 }
497 } else { // linda is cancelled 499 } else { // linda is cancelled
498 // do nothing and return nil,lanes.cancel_error 500 // do nothing and return nil,lanes.cancel_error
@@ -500,7 +502,7 @@ LUAG_FUNC(linda_limit)
500 kCancelError.pushKey(L_); 502 kCancelError.pushKey(L_);
501 _pushed.emplace(2); 503 _pushed.emplace(2);
502 } 504 }
503 // propagate pushed boolean if any 505 // propagate returned values
504 return _pushed.value(); 506 return _pushed.value();
505 } 507 }
506 }; 508 };
@@ -807,7 +809,7 @@ LUAG_FUNC(linda_send)
807// ################################################################################################# 809// #################################################################################################
808 810
809/* 811/*
810 * [true|nil,lanes.cancel_error] = linda:set(key_num|str|bool|lightuserdata [, value [, ...]]) 812 * (boolean,string)|(nil,lanes.cancel_error) = linda:set(key_num|str|bool|lightuserdata [, value [, ...]])
811 * 813 *
812 * Set one or more value to Linda. Ignores limits. 814 * Set one or more value to Linda. Ignores limits.
813 * 815 *
@@ -827,13 +829,13 @@ LUAG_FUNC(linda_set)
827 Keeper* const _keeper{ _linda->whichKeeper() }; 829 Keeper* const _keeper{ _linda->whichKeeper() };
828 _pushed = keeper_call(_keeper->K, KEEPER_API(set), L_, _linda, 2); 830 _pushed = keeper_call(_keeper->K, KEEPER_API(set), L_, _linda, 2);
829 if (_pushed.has_value()) { // no error? 831 if (_pushed.has_value()) { // no error?
830 LUA_ASSERT(L_, _pushed.value() == 1 && luaG_type(L_, -1) == LuaType::BOOLEAN); 832 LUA_ASSERT(L_, _pushed.value() == 2 && luaG_type(L_, -1) == LuaType::STRING && luaG_type(L_, -2) == LuaType::BOOLEAN);
831 833
832 if (_has_data) { 834 if (_has_data) {
833 // we put some data in the slot, tell readers that they should wake 835 // we put some data in the slot, tell readers that they should wake
834 _linda->writeHappened.notify_all(); // To be done from within the 'K' locking area 836 _linda->writeHappened.notify_all(); // To be done from within the 'K' locking area
835 } 837 }
836 if (lua_toboolean(L_, -1)) { 838 if (lua_toboolean(L_, -2)) {
837 // the key was full, but it is no longer the case, tell writers they should wake 839 // the key was full, but it is no longer the case, tell writers they should wake
838 _linda->readHappened.notify_all(); // To be done from within the 'K' locking area 840 _linda->readHappened.notify_all(); // To be done from within the 'K' locking area
839 } 841 }