aboutsummaryrefslogtreecommitdiff
path: root/src/linda.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/linda.cpp')
-rw-r--r--src/linda.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/linda.cpp b/src/linda.cpp
index 77dc4cb..14eba2d 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -216,11 +216,8 @@ LUAG_FUNC(linda_protected_call)
216LUAG_FUNC(linda_send) 216LUAG_FUNC(linda_send)
217{ 217{
218 Linda* const linda{ lua_toLinda<false>(L, 1) }; 218 Linda* const linda{ lua_toLinda<false>(L, 1) };
219 bool ret{ false }; 219 time_d timeout{ -1.0 };
220 CancelRequest cancel{ CancelRequest::None }; 220 int key_i{ 2 }; // index of first key, if timeout not there
221 int pushed;
222 time_d timeout = -1.0;
223 int key_i = 2; // index of first key, if timeout not there
224 221
225 if (lua_type(L, 2) == LUA_TNUMBER) // we don't want to use lua_isnumber() because of autocoercion 222 if (lua_type(L, 2) == LUA_TNUMBER) // we don't want to use lua_isnumber() because of autocoercion
226 { 223 {
@@ -250,7 +247,7 @@ LUAG_FUNC(linda_send)
250 if (as_nil_sentinel) 247 if (as_nil_sentinel)
251 { 248 {
252 // send a single nil if nothing is provided 249 // send a single nil if nothing is provided
253 NIL_SENTINEL.push(L); 250 NIL_SENTINEL.pushKey(L);
254 } 251 }
255 else 252 else
256 { 253 {
@@ -260,9 +257,11 @@ LUAG_FUNC(linda_send)
260 257
261 // convert nils to some special non-nil sentinel in sent values 258 // convert nils to some special non-nil sentinel in sent values
262 keeper_toggle_nil_sentinels(L, key_i + 1, eLM_ToKeeper); 259 keeper_toggle_nil_sentinels(L, key_i + 1, eLM_ToKeeper);
263 260 bool ret{ false };
261 CancelRequest cancel{ CancelRequest::None };
262 int pushed{ 0 };
264 { 263 {
265 Lane* const lane{ get_lane_from_registry(L) }; 264 Lane* const lane{ LANE_POINTER_REGKEY.readLightUserDataValue<Lane>(L) };
266 Keeper* const K{ which_keeper(linda->U->keepers, linda->hashSeed()) }; 265 Keeper* const K{ which_keeper(linda->U->keepers, linda->hashSeed()) };
267 lua_State* const KL{ K ? K->L : nullptr }; 266 lua_State* const KL{ K ? K->L : nullptr };
268 if (KL == nullptr) 267 if (KL == nullptr)
@@ -339,7 +338,7 @@ LUAG_FUNC(linda_send)
339 { 338 {
340 case CancelRequest::Soft: 339 case CancelRequest::Soft:
341 // if user wants to soft-cancel, the call returns lanes.cancel_error 340 // if user wants to soft-cancel, the call returns lanes.cancel_error
342 CANCEL_ERROR.push(L); 341 CANCEL_ERROR.pushKey(L);
343 return 1; 342 return 1;
344 343
345 case CancelRequest::Hard: 344 case CancelRequest::Hard:
@@ -387,7 +386,7 @@ LUAG_FUNC(linda_receive)
387 keeper_api_t keeper_receive; 386 keeper_api_t keeper_receive;
388 int expected_pushed_min{ 0 }, expected_pushed_max{ 0 }; 387 int expected_pushed_min{ 0 }, expected_pushed_max{ 0 };
389 // are we in batched mode? 388 // are we in batched mode?
390 BATCH_SENTINEL.push(L); 389 BATCH_SENTINEL.pushKey(L);
391 int const is_batched{ lua501_equal(L, key_i, -1) }; 390 int const is_batched{ lua501_equal(L, key_i, -1) };
392 lua_pop(L, 1); 391 lua_pop(L, 1);
393 if (is_batched) 392 if (is_batched)
@@ -419,7 +418,7 @@ LUAG_FUNC(linda_receive)
419 expected_pushed_min = expected_pushed_max = 2; 418 expected_pushed_min = expected_pushed_max = 2;
420 } 419 }
421 420
422 Lane* const lane{ get_lane_from_registry(L) }; 421 Lane* const lane{ LANE_POINTER_REGKEY.readLightUserDataValue<Lane>(L) };
423 Keeper* const K{ which_keeper(linda->U->keepers, linda->hashSeed()) }; 422 Keeper* const K{ which_keeper(linda->U->keepers, linda->hashSeed()) };
424 if (K == nullptr) 423 if (K == nullptr)
425 return 0; 424 return 0;
@@ -492,7 +491,7 @@ LUAG_FUNC(linda_receive)
492 { 491 {
493 case CancelRequest::Soft: 492 case CancelRequest::Soft:
494 // if user wants to soft-cancel, the call returns CANCEL_ERROR 493 // if user wants to soft-cancel, the call returns CANCEL_ERROR
495 CANCEL_ERROR.push(L); 494 CANCEL_ERROR.pushKey(L);
496 return 1; 495 return 1;
497 496
498 case CancelRequest::Hard: 497 case CancelRequest::Hard:
@@ -551,7 +550,7 @@ LUAG_FUNC(linda_set)
551 else // linda is cancelled 550 else // linda is cancelled
552 { 551 {
553 // do nothing and return lanes.cancel_error 552 // do nothing and return lanes.cancel_error
554 CANCEL_ERROR.push(L); 553 CANCEL_ERROR.pushKey(L);
555 pushed = 1; 554 pushed = 1;
556 } 555 }
557 556
@@ -610,7 +609,7 @@ LUAG_FUNC(linda_get)
610 else // linda is cancelled 609 else // linda is cancelled
611 { 610 {
612 // do nothing and return lanes.cancel_error 611 // do nothing and return lanes.cancel_error
613 CANCEL_ERROR.push(L); 612 CANCEL_ERROR.pushKey(L);
614 pushed = 1; 613 pushed = 1;
615 } 614 }
616 // an error can be raised if we attempt to read an unregistered function 615 // an error can be raised if we attempt to read an unregistered function
@@ -655,7 +654,7 @@ LUAG_FUNC( linda_limit)
655 else // linda is cancelled 654 else // linda is cancelled
656 { 655 {
657 // do nothing and return lanes.cancel_error 656 // do nothing and return lanes.cancel_error
658 CANCEL_ERROR.push(L); 657 CANCEL_ERROR.pushKey(L);
659 pushed = 1; 658 pushed = 1;
660 } 659 }
661 // propagate pushed boolean if any 660 // propagate pushed boolean if any
@@ -961,10 +960,10 @@ static void* linda_id( lua_State* L, DeepOp op_)
961 lua_setfield(L, -2, "dump"); 960 lua_setfield(L, -2, "dump");
962 961
963 // some constants 962 // some constants
964 BATCH_SENTINEL.push(L); 963 BATCH_SENTINEL.pushKey(L);
965 lua_setfield(L, -2, "batched"); 964 lua_setfield(L, -2, "batched");
966 965
967 NIL_SENTINEL.push(L); 966 NIL_SENTINEL.pushKey(L);
968 lua_setfield(L, -2, "null"); 967 lua_setfield(L, -2, "null");
969 968
970 STACK_CHECK(L, 1); 969 STACK_CHECK(L, 1);