aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-06-10 16:49:58 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-06-10 16:49:58 +0200
commitae582acdb1bfb3fb4171682b884545d174e95aa9 (patch)
treeb0c9c0b14f6d57cd8ce1c14d4d23df1adb0bc539 /src
parent3f5c16116a3a7740ac4ac62b663661d772543c2e (diff)
downloadlanes-ae582acdb1bfb3fb4171682b884545d174e95aa9.tar.gz
lanes-ae582acdb1bfb3fb4171682b884545d174e95aa9.tar.bz2
lanes-ae582acdb1bfb3fb4171682b884545d174e95aa9.zip
linda:send() returns nil,<something> in case of error
Diffstat (limited to 'src')
-rw-r--r--src/lanes.cpp4
-rw-r--r--src/lanes.lua3
-rw-r--r--src/linda.cpp16
3 files changed, 16 insertions, 7 deletions
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
867{ 867{
868 STACK_CHECK_START_REL(L_, 0); 868 STACK_CHECK_START_REL(L_, 0);
869 // pre-require lanes.core so that when lanes.lua calls require "lanes.core" it finds it is already loaded 869 // pre-require lanes.core so that when lanes.lua calls require "lanes.core" it finds it is already loaded
870 luaL_requiref(L_, "lanes.core", luaopen_lanes_core, 0); // L_: ... lanes.core 870 luaL_requiref(L_, kLanesCoreLibName, luaopen_lanes_core, 0); // L_: ... lanes.core
871 lua_pop(L_, 1); // L_: ... 871 lua_pop(L_, 1); // L_: ...
872 STACK_CHECK(L_, 0); 872 STACK_CHECK(L_, 0);
873 // call user-provided function that runs the chunk "lanes.lua" from wherever they stored it 873 // call user-provided function that runs the chunk "lanes.lua" from wherever they stored it
874 luaL_requiref(L_, "lanes", _luaopen_lanes ? _luaopen_lanes : default_luaopen_lanes, 0); // L_: ... lanes 874 luaL_requiref(L_, kLanesLibName, _luaopen_lanes ? _luaopen_lanes : default_luaopen_lanes, 0); // L_: ... lanes
875 STACK_CHECK(L_, 1); 875 STACK_CHECK(L_, 1);
876} 876}
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_)
728 return function(diff_) 728 return function(diff_)
729 -- 'nil' allows 'key_' to be numeric 729 -- 'nil' allows 'key_' to be numeric
730 -- suspends until our 'true' is in 730 -- suspends until our 'true' is in
731 if linda_:send(nil, key_, true) == cancel_error then 731 local _res, _err = linda_:send(nil, key_, true)
732 if _err == cancel_error then
732 return cancel_error 733 return cancel_error
733 end 734 end
734 local val = linda_:get(key_) 735 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)
709 709
710 switch (_cancel) { 710 switch (_cancel) {
711 case CancelRequest::Soft: 711 case CancelRequest::Soft:
712 // if user wants to soft-cancel, the call returns lanes.cancel_error 712 // if user wants to soft-cancel, the call returns nil, kCancelError
713 lua_pushnil(L_);
713 kCancelError.pushKey(L_); 714 kCancelError.pushKey(L_);
714 return 1; 715 return 2;
715 716
716 case CancelRequest::Hard: 717 case CancelRequest::Hard:
717 // raise an error interrupting execution only in case of hard cancel 718 // raise an error interrupting execution only in case of hard cancel
718 raise_cancel_error(L_); // raises an error and doesn't return 719 raise_cancel_error(L_); // raises an error and doesn't return
719 720
720 default: 721 default:
721 lua_pushboolean(L_, _ret); // true (success) or false (timeout) 722 if (_ret) {
722 return 1; 723 lua_pushboolean(L_, _ret); // true (success)
724 return 1;
725 } else {
726 // not enough room in the Linda slot to fulfill the request, return nil, "timeout"
727 lua_pushnil(L_);
728 std::ignore = luaG_pushstring(L_, "timeout");
729 return 2;
730 }
723 } 731 }
724 }; 732 };
725 return Linda::ProtectedCall(L_, _send); 733 return Linda::ProtectedCall(L_, _send);