aboutsummaryrefslogtreecommitdiff
path: root/src/linda.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/linda.cpp')
-rw-r--r--src/linda.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/linda.cpp b/src/linda.cpp
index 5832f22..fa27871 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -121,12 +121,11 @@ LUAG_FUNC( linda_protected_call)
121LUAG_FUNC( linda_send) 121LUAG_FUNC( linda_send)
122{ 122{
123 struct s_Linda* linda = lua_toLinda( L, 1); 123 struct s_Linda* linda = lua_toLinda( L, 1);
124 bool_t ret = FALSE; 124 bool ret{ false };
125 enum e_cancel_request cancel = CANCEL_NONE; 125 enum e_cancel_request cancel = CANCEL_NONE;
126 int pushed; 126 int pushed;
127 time_d timeout = -1.0; 127 time_d timeout = -1.0;
128 uint_t key_i = 2; // index of first key, if timeout not there 128 uint_t key_i = 2; // index of first key, if timeout not there
129 bool_t as_nil_sentinel; // if not NULL, send() will silently send a single nil if nothing is provided
130 129
131 if( lua_type( L, 2) == LUA_TNUMBER) // we don't want to use lua_isnumber() because of autocoercion 130 if( lua_type( L, 2) == LUA_TNUMBER) // we don't want to use lua_isnumber() because of autocoercion
132 { 131 {
@@ -138,7 +137,7 @@ LUAG_FUNC( linda_send)
138 ++ key_i; 137 ++ key_i;
139 } 138 }
140 139
141 as_nil_sentinel = equal_unique_key( L, key_i, NIL_SENTINEL); 140 bool const as_nil_sentinel{ equal_unique_key(L, key_i, NIL_SENTINEL) };// if not nullptr, send() will silently send a single nil if nothing is provided
142 if( as_nil_sentinel) 141 if( as_nil_sentinel)
143 { 142 {
144 // the real key to send data to is after the NIL_SENTINEL marker 143 // the real key to send data to is after the NIL_SENTINEL marker
@@ -168,13 +167,12 @@ LUAG_FUNC( linda_send)
168 keeper_toggle_nil_sentinels( L, key_i + 1, eLM_ToKeeper); 167 keeper_toggle_nil_sentinels( L, key_i + 1, eLM_ToKeeper);
169 168
170 { 169 {
171 bool_t try_again = TRUE;
172 Lane* const s = get_lane_from_registry( L); 170 Lane* const s = get_lane_from_registry( L);
173 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); 171 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda));
174 lua_State* KL = K ? K->L : nullptr; // need to do this for 'STACK_CHECK' 172 lua_State* KL = K ? K->L : nullptr; // need to do this for 'STACK_CHECK'
175 if( KL == nullptr) return 0; 173 if( KL == nullptr) return 0;
176 STACK_CHECK( KL, 0); 174 STACK_CHECK( KL, 0);
177 for( ;;) 175 for(bool try_again{ true };;)
178 { 176 {
179 if( s != nullptr) 177 if( s != nullptr)
180 { 178 {
@@ -196,7 +194,7 @@ LUAG_FUNC( linda_send)
196 } 194 }
197 ASSERT_L( pushed == 1); 195 ASSERT_L( pushed == 1);
198 196
199 ret = lua_toboolean( L, -1); 197 ret = lua_toboolean( L, -1) ? true : false;
200 lua_pop( L, 1); 198 lua_pop( L, 1);
201 199
202 if( ret) 200 if( ret)
@@ -328,11 +326,10 @@ LUAG_FUNC( linda_receive)
328 } 326 }
329 327
330 { 328 {
331 bool_t try_again = TRUE;
332 Lane* const s = get_lane_from_registry( L); 329 Lane* const s = get_lane_from_registry( L);
333 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); 330 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda));
334 if( K == nullptr) return 0; 331 if( K == nullptr) return 0;
335 for( ;;) 332 for (bool try_again{ true };;)
336 { 333 {
337 if( s != nullptr) 334 if( s != nullptr)
338 { 335 {
@@ -425,7 +422,7 @@ LUAG_FUNC( linda_set)
425{ 422{
426 struct s_Linda* const linda = lua_toLinda( L, 1); 423 struct s_Linda* const linda = lua_toLinda( L, 1);
427 int pushed; 424 int pushed;
428 bool_t has_value = lua_gettop( L) > 2; 425 bool const has_value{ lua_gettop(L) > 2 };
429 426
430 // make sure the key is of a valid type (throws an error if not the case) 427 // make sure the key is of a valid type (throws an error if not the case)
431 check_key_types( L, 2, 2); 428 check_key_types( L, 2, 2);
@@ -647,7 +644,7 @@ LUAG_FUNC( linda_deep)
647* Useful for concatenation or debugging purposes 644* Useful for concatenation or debugging purposes
648*/ 645*/
649 646
650static int linda_tostring( lua_State* L, int idx_, bool_t opt_) 647static int linda_tostring( lua_State* L, int idx_, bool opt_)
651{ 648{
652 struct s_Linda* linda = (struct s_Linda*) luaG_todeep( L, linda_id, idx_); 649 struct s_Linda* linda = (struct s_Linda*) luaG_todeep( L, linda_id, idx_);
653 if( !opt_) 650 if( !opt_)
@@ -670,7 +667,7 @@ static int linda_tostring( lua_State* L, int idx_, bool_t opt_)
670 667
671LUAG_FUNC( linda_tostring) 668LUAG_FUNC( linda_tostring)
672{ 669{
673 return linda_tostring( L, 1, FALSE); 670 return linda_tostring( L, 1, false);
674} 671}
675 672
676 673
@@ -683,16 +680,16 @@ LUAG_FUNC( linda_tostring)
683*/ 680*/
684LUAG_FUNC( linda_concat) 681LUAG_FUNC( linda_concat)
685{ // linda1? linda2? 682{ // linda1? linda2?
686 bool_t atLeastOneLinda = FALSE; 683 bool atLeastOneLinda{ false };
687 // Lua semantics enforce that one of the 2 arguments is a Linda, but not necessarily both. 684 // Lua semantics enforce that one of the 2 arguments is a Linda, but not necessarily both.
688 if( linda_tostring( L, 1, TRUE)) 685 if( linda_tostring( L, 1, true))
689 { 686 {
690 atLeastOneLinda = TRUE; 687 atLeastOneLinda = true;
691 lua_replace( L, 1); 688 lua_replace( L, 1);
692 } 689 }
693 if( linda_tostring( L, 2, TRUE)) 690 if( linda_tostring( L, 2, true))
694 { 691 {
695 atLeastOneLinda = TRUE; 692 atLeastOneLinda = true;
696 lua_replace( L, 2); 693 lua_replace( L, 2);
697 } 694 }
698 if( !atLeastOneLinda) // should not be possible 695 if( !atLeastOneLinda) // should not be possible
@@ -727,7 +724,7 @@ LUAG_FUNC( linda_towatch)
727 if( pushed == 0) 724 if( pushed == 0)
728 { 725 {
729 // if the linda is empty, don't return nil 726 // if the linda is empty, don't return nil
730 pushed = linda_tostring( L, 1, FALSE); 727 pushed = linda_tostring( L, 1, false);
731 } 728 }
732 return pushed; 729 return pushed;
733} 730}