aboutsummaryrefslogtreecommitdiff
path: root/src/linda.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/linda.cpp')
-rw-r--r--src/linda.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/linda.cpp b/src/linda.cpp
index eac6458..5832f22 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -63,7 +63,7 @@ static void* linda_id( lua_State*, DeepOp);
63static inline struct s_Linda* lua_toLinda( lua_State* L, int idx_) 63static inline struct s_Linda* lua_toLinda( lua_State* L, int idx_)
64{ 64{
65 struct s_Linda* linda = (struct s_Linda*) luaG_todeep( L, linda_id, idx_); 65 struct s_Linda* linda = (struct s_Linda*) luaG_todeep( L, linda_id, idx_);
66 luaL_argcheck( L, linda != NULL, idx_, "expecting a linda object"); 66 luaL_argcheck( L, linda != nullptr, idx_, "expecting a linda object");
67 return linda; 67 return linda;
68} 68}
69 69
@@ -88,8 +88,8 @@ LUAG_FUNC( linda_protected_call)
88 88
89 // acquire the keeper 89 // acquire the keeper
90 Keeper* K = keeper_acquire( linda->U->keepers, LINDA_KEEPER_HASHSEED(linda)); 90 Keeper* K = keeper_acquire( linda->U->keepers, LINDA_KEEPER_HASHSEED(linda));
91 lua_State* KL = K ? K->L : NULL; // need to do this for 'STACK_CHECK' 91 lua_State* KL = K ? K->L : nullptr; // need to do this for 'STACK_CHECK'
92 if( KL == NULL) return 0; 92 if( KL == nullptr) return 0;
93 93
94 // retrieve the actual function to be called and move it before the arguments 94 // retrieve the actual function to be called and move it before the arguments
95 lua_pushvalue( L, lua_upvalueindex( 1)); 95 lua_pushvalue( L, lua_upvalueindex( 1));
@@ -171,12 +171,12 @@ LUAG_FUNC( linda_send)
171 bool_t try_again = TRUE; 171 bool_t try_again = TRUE;
172 Lane* const s = get_lane_from_registry( L); 172 Lane* const s = get_lane_from_registry( L);
173 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); 173 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda));
174 lua_State* KL = K ? K->L : NULL; // need to do this for 'STACK_CHECK' 174 lua_State* KL = K ? K->L : nullptr; // need to do this for 'STACK_CHECK'
175 if( KL == NULL) return 0; 175 if( KL == nullptr) return 0;
176 STACK_CHECK( KL, 0); 176 STACK_CHECK( KL, 0);
177 for( ;;) 177 for( ;;)
178 { 178 {
179 if( s != NULL) 179 if( s != nullptr)
180 { 180 {
181 cancel = s->cancel_request; 181 cancel = s->cancel_request;
182 } 182 }
@@ -215,20 +215,20 @@ LUAG_FUNC( linda_send)
215 // storage limit hit, wait until timeout or signalled that we should try again 215 // storage limit hit, wait until timeout or signalled that we should try again
216 { 216 {
217 enum e_status prev_status = ERROR_ST; // prevent 'might be used uninitialized' warnings 217 enum e_status prev_status = ERROR_ST; // prevent 'might be used uninitialized' warnings
218 if( s != NULL) 218 if( s != nullptr)
219 { 219 {
220 // change status of lane to "waiting" 220 // change status of lane to "waiting"
221 prev_status = s->status; // RUNNING, most likely 221 prev_status = s->status; // RUNNING, most likely
222 ASSERT_L( prev_status == RUNNING); // but check, just in case 222 ASSERT_L( prev_status == RUNNING); // but check, just in case
223 s->status = WAITING; 223 s->status = WAITING;
224 ASSERT_L( s->waiting_on == NULL); 224 ASSERT_L( s->waiting_on == nullptr);
225 s->waiting_on = &linda->read_happened; 225 s->waiting_on = &linda->read_happened;
226 } 226 }
227 // could not send because no room: wait until some data was read before trying again, or until timeout is reached 227 // could not send because no room: wait until some data was read before trying again, or until timeout is reached
228 try_again = SIGNAL_WAIT( &linda->read_happened, &K->keeper_cs, timeout); 228 try_again = SIGNAL_WAIT( &linda->read_happened, &K->keeper_cs, timeout);
229 if( s != NULL) 229 if( s != nullptr)
230 { 230 {
231 s->waiting_on = NULL; 231 s->waiting_on = nullptr;
232 s->status = prev_status; 232 s->status = prev_status;
233 } 233 }
234 } 234 }
@@ -331,10 +331,10 @@ LUAG_FUNC( linda_receive)
331 bool_t try_again = TRUE; 331 bool_t try_again = TRUE;
332 Lane* const s = get_lane_from_registry( L); 332 Lane* const s = get_lane_from_registry( L);
333 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); 333 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda));
334 if( K == NULL) return 0; 334 if( K == nullptr) return 0;
335 for( ;;) 335 for( ;;)
336 { 336 {
337 if( s != NULL) 337 if( s != nullptr)
338 { 338 {
339 cancel = s->cancel_request; 339 cancel = s->cancel_request;
340 } 340 }
@@ -371,20 +371,20 @@ LUAG_FUNC( linda_receive)
371 // nothing received, wait until timeout or signalled that we should try again 371 // nothing received, wait until timeout or signalled that we should try again
372 { 372 {
373 enum e_status prev_status = ERROR_ST; // prevent 'might be used uninitialized' warnings 373 enum e_status prev_status = ERROR_ST; // prevent 'might be used uninitialized' warnings
374 if( s != NULL) 374 if( s != nullptr)
375 { 375 {
376 // change status of lane to "waiting" 376 // change status of lane to "waiting"
377 prev_status = s->status; // RUNNING, most likely 377 prev_status = s->status; // RUNNING, most likely
378 ASSERT_L( prev_status == RUNNING); // but check, just in case 378 ASSERT_L( prev_status == RUNNING); // but check, just in case
379 s->status = WAITING; 379 s->status = WAITING;
380 ASSERT_L( s->waiting_on == NULL); 380 ASSERT_L( s->waiting_on == nullptr);
381 s->waiting_on = &linda->write_happened; 381 s->waiting_on = &linda->write_happened;
382 } 382 }
383 // not enough data to read: wakeup when data was sent, or when timeout is reached 383 // not enough data to read: wakeup when data was sent, or when timeout is reached
384 try_again = SIGNAL_WAIT( &linda->write_happened, &K->keeper_cs, timeout); 384 try_again = SIGNAL_WAIT( &linda->write_happened, &K->keeper_cs, timeout);
385 if( s != NULL) 385 if( s != nullptr)
386 { 386 {
387 s->waiting_on = NULL; 387 s->waiting_on = nullptr;
388 s->status = prev_status; 388 s->status = prev_status;
389 } 389 }
390 } 390 }
@@ -654,7 +654,7 @@ static int linda_tostring( lua_State* L, int idx_, bool_t opt_)
654 { 654 {
655 luaL_argcheck( L, linda, idx_, "expecting a linda object"); 655 luaL_argcheck( L, linda, idx_, "expecting a linda object");
656 } 656 }
657 if( linda != NULL) 657 if( linda != nullptr)
658 { 658 {
659 char text[128]; 659 char text[128];
660 int len; 660 int len;
@@ -764,7 +764,7 @@ static void* linda_id( lua_State* L, DeepOp op_)
764 { 764 {
765 struct s_Linda* s; 765 struct s_Linda* s;
766 size_t name_len = 0; 766 size_t name_len = 0;
767 char const* linda_name = NULL; 767 char const* linda_name = nullptr;
768 unsigned long linda_group = 0; 768 unsigned long linda_group = 0;
769 // should have a string and/or a number of the stack as parameters (name and group) 769 // should have a string and/or a number of the stack as parameters (name and group)
770 switch( lua_gettop( L)) 770 switch( lua_gettop( L))
@@ -797,7 +797,7 @@ static void* linda_id( lua_State* L, DeepOp op_)
797 { 797 {
798 Universe* const U = universe_get(L); 798 Universe* const U = universe_get(L);
799 AllocatorDefinition* const allocD = &U->internal_allocator; 799 AllocatorDefinition* const allocD = &U->internal_allocator;
800 s = (struct s_Linda*) allocD->allocF(allocD->allocUD, NULL, 0, sizeof(struct s_Linda) + name_len); // terminating 0 is already included 800 s = (struct s_Linda*) allocD->allocF(allocD->allocUD, nullptr, 0, sizeof(struct s_Linda) + name_len); // terminating 0 is already included
801 } 801 }
802 if( s) 802 if( s)
803 { 803 {
@@ -821,7 +821,7 @@ static void* linda_id( lua_State* L, DeepOp op_)
821 821
822 // Clean associated structures in the keeper state. 822 // Clean associated structures in the keeper state.
823 K = keeper_acquire( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); 823 K = keeper_acquire( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda));
824 if( K && K->L) // can be NULL if this happens during main state shutdown (lanes is GC'ed -> no keepers -> no need to cleanup) 824 if( K && K->L) // can be nullptr if this happens during main state shutdown (lanes is GC'ed -> no keepers -> no need to cleanup)
825 { 825 {
826 // hopefully this won't ever raise an error as we would jump to the closest pcall site while forgetting to release the keeper mutex... 826 // hopefully this won't ever raise an error as we would jump to the closest pcall site while forgetting to release the keeper mutex...
827 keeper_call( linda->U, K->L, KEEPER_API( clear), L, linda, 0); 827 keeper_call( linda->U, K->L, KEEPER_API( clear), L, linda, 0);
@@ -836,7 +836,7 @@ static void* linda_id( lua_State* L, DeepOp op_)
836 AllocatorDefinition* const allocD = &U->internal_allocator; 836 AllocatorDefinition* const allocD = &U->internal_allocator;
837 (void) allocD->allocF(allocD->allocUD, linda, sizeof(struct s_Linda) + strlen(linda->name), 0); 837 (void) allocD->allocF(allocD->allocUD, linda, sizeof(struct s_Linda) + strlen(linda->name), 0);
838 } 838 }
839 return NULL; 839 return nullptr;
840 } 840 }
841 841
842 case eDO_metatable: 842 case eDO_metatable:
@@ -908,7 +908,7 @@ static void* linda_id( lua_State* L, DeepOp op_)
908 lua_setfield( L, -2, "null"); 908 lua_setfield( L, -2, "null");
909 909
910 STACK_END( L, 1); 910 STACK_END( L, 1);
911 return NULL; 911 return nullptr;
912 } 912 }
913 913
914 case eDO_module: 914 case eDO_module:
@@ -917,7 +917,7 @@ static void* linda_id( lua_State* L, DeepOp op_)
917 // in other words, forever. 917 // in other words, forever.
918 default: 918 default:
919 { 919 {
920 return NULL; 920 return nullptr;
921 } 921 }
922 } 922 }
923} 923}