From ae582acdb1bfb3fb4171682b884545d174e95aa9 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Mon, 10 Jun 2024 16:49:58 +0200 Subject: linda:send() returns nil, in case of error --- src/lanes.cpp | 4 ++-- src/lanes.lua | 3 ++- src/linda.cpp | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/lanes.cpp b/src/lanes.cpp index 9b3b28c..5d40ed4 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp @@ -867,10 +867,10 @@ LANES_API void luaopen_lanes_embedded(lua_State* L_, lua_CFunction _luaopen_lane { STACK_CHECK_START_REL(L_, 0); // pre-require lanes.core so that when lanes.lua calls require "lanes.core" it finds it is already loaded - luaL_requiref(L_, "lanes.core", luaopen_lanes_core, 0); // L_: ... lanes.core + luaL_requiref(L_, kLanesCoreLibName, luaopen_lanes_core, 0); // L_: ... lanes.core lua_pop(L_, 1); // L_: ... STACK_CHECK(L_, 0); // call user-provided function that runs the chunk "lanes.lua" from wherever they stored it - luaL_requiref(L_, "lanes", _luaopen_lanes ? _luaopen_lanes : default_luaopen_lanes, 0); // L_: ... lanes + luaL_requiref(L_, kLanesLibName, _luaopen_lanes ? _luaopen_lanes : default_luaopen_lanes, 0); // L_: ... lanes STACK_CHECK(L_, 1); } diff --git a/src/lanes.lua b/src/lanes.lua index 95c4eff..92e773a 100644 --- a/src/lanes.lua +++ b/src/lanes.lua @@ -728,7 +728,8 @@ local genatomic = function(linda_, key_, initial_val_) return function(diff_) -- 'nil' allows 'key_' to be numeric -- suspends until our 'true' is in - if linda_:send(nil, key_, true) == cancel_error then + local _res, _err = linda_:send(nil, key_, true) + if _err == cancel_error then return cancel_error end local val = linda_:get(key_) diff --git a/src/linda.cpp b/src/linda.cpp index 4dc2162..1bd5d16 100644 --- a/src/linda.cpp +++ b/src/linda.cpp @@ -709,17 +709,25 @@ LUAG_FUNC(linda_send) switch (_cancel) { case CancelRequest::Soft: - // if user wants to soft-cancel, the call returns lanes.cancel_error + // if user wants to soft-cancel, the call returns nil, kCancelError + lua_pushnil(L_); kCancelError.pushKey(L_); - return 1; + return 2; case CancelRequest::Hard: // raise an error interrupting execution only in case of hard cancel raise_cancel_error(L_); // raises an error and doesn't return default: - lua_pushboolean(L_, _ret); // true (success) or false (timeout) - return 1; + if (_ret) { + lua_pushboolean(L_, _ret); // true (success) + return 1; + } else { + // not enough room in the Linda slot to fulfill the request, return nil, "timeout" + lua_pushnil(L_); + std::ignore = luaG_pushstring(L_, "timeout"); + return 2; + } } }; return Linda::ProtectedCall(L_, _send); -- cgit v1.2.3-55-g6feb