aboutsummaryrefslogtreecommitdiff
path: root/src/linda.cpp
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-05-31 17:04:17 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-05-31 17:04:17 +0200
commitf7a38b5681ebf7429828fca9a9f7c109df853d54 (patch)
tree9c4e702071a6915719ca639790936b35ed1ed828 /src/linda.cpp
parent95e5bf6461be6e227466911d5e3a683d149df725 (diff)
downloadlanes-f7a38b5681ebf7429828fca9a9f7c109df853d54.tar.gz
lanes-f7a38b5681ebf7429828fca9a9f7c109df853d54.tar.bz2
lanes-f7a38b5681ebf7429828fca9a9f7c109df853d54.zip
Some API changes
* lanes.timers() can return nil, cancel_error if interrupted * linda:receive() always return a k,v, where k is nil when v is "timeout" or cancel_error * lanes.sleep returns nil, "timeout" during normal operations
Diffstat (limited to 'src/linda.cpp')
-rw-r--r--src/linda.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/linda.cpp b/src/linda.cpp
index 4ab89ab..2a31799 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -553,17 +553,30 @@ LUAG_FUNC(linda_receive)
553 } 553 }
554 554
555 switch (_cancel) { 555 switch (_cancel) {
556 case CancelRequest::None:
557 {
558 int const _nbPushed{ _pushed.value() };
559 if (_nbPushed == 0) {
560 // not enough data in the linda slot to fulfill the request, return nil, "timeout"
561 lua_pushnil(L_);
562 std::ignore = lua_pushstringview(L_, "timeout");
563 return 2;
564 }
565 return _nbPushed;
566 }
567
556 case CancelRequest::Soft: 568 case CancelRequest::Soft:
557 // if user wants to soft-cancel, the call returns kCancelError 569 // if user wants to soft-cancel, the call returns nil, kCancelError
570 lua_pushnil(L_);
558 kCancelError.pushKey(L_); 571 kCancelError.pushKey(L_);
559 return 1; 572 return 2;
560 573
561 case CancelRequest::Hard: 574 case CancelRequest::Hard:
562 // raise an error interrupting execution only in case of hard cancel 575 // raise an error interrupting execution only in case of hard cancel
563 raise_cancel_error(L_); // raises an error and doesn't return 576 raise_cancel_error(L_); // raises an error and doesn't return
564 577
565 default: 578 default:
566 return _pushed.value(); 579 raise_luaL_error(L_, "internal error: unknown cancel request");
567 } 580 }
568 }; 581 };
569 return Linda::ProtectedCall(L_, _receive); 582 return Linda::ProtectedCall(L_, _receive);