aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cancel.cpp6
-rw-r--r--src/keeper.cpp36
-rw-r--r--src/lanes.cpp62
-rw-r--r--src/lanes_private.h6
-rw-r--r--src/linda.cpp46
-rw-r--r--src/universe.cpp2
6 files changed, 79 insertions, 79 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp
index 0a5adb6..8558008 100644
--- a/src/cancel.cpp
+++ b/src/cancel.cpp
@@ -84,7 +84,7 @@ static void cancel_hook( lua_State* L, lua_Debug* ar)
84 DEBUGSPEW_CODE( fprintf( stderr, "cancel_hook\n")); 84 DEBUGSPEW_CODE( fprintf( stderr, "cancel_hook\n"));
85 if( cancel_test( L) != CANCEL_NONE) 85 if( cancel_test( L) != CANCEL_NONE)
86 { 86 {
87 lua_sethook( L, NULL, 0, 0); 87 lua_sethook( L, nullptr, 0, 0);
88 cancel_error( L); 88 cancel_error( L);
89 } 89 }
90} 90}
@@ -119,7 +119,7 @@ static cancel_result thread_cancel_soft( Lane* s, double secs_, bool_t wake_lind
119 if( wake_lindas_) // wake the thread so that execution returns from any pending linda operation if desired 119 if( wake_lindas_) // wake the thread so that execution returns from any pending linda operation if desired
120 { 120 {
121 SIGNAL_T *waiting_on = s->waiting_on; 121 SIGNAL_T *waiting_on = s->waiting_on;
122 if( s->status == WAITING && waiting_on != NULL) 122 if( s->status == WAITING && waiting_on != nullptr)
123 { 123 {
124 SIGNAL_ALL( waiting_on); 124 SIGNAL_ALL( waiting_on);
125 } 125 }
@@ -137,7 +137,7 @@ static cancel_result thread_cancel_hard( lua_State* L, Lane* s, double secs_, bo
137 s->cancel_request = CANCEL_HARD; // it's now signaled to stop 137 s->cancel_request = CANCEL_HARD; // it's now signaled to stop
138 { 138 {
139 SIGNAL_T *waiting_on = s->waiting_on; 139 SIGNAL_T *waiting_on = s->waiting_on;
140 if( s->status == WAITING && waiting_on != NULL) 140 if( s->status == WAITING && waiting_on != nullptr)
141 { 141 {
142 SIGNAL_ALL( waiting_on); 142 SIGNAL_ALL( waiting_on);
143 } 143 }
diff --git a/src/keeper.cpp b/src/keeper.cpp
index 8aa734a..10fba2b 100644
--- a/src/keeper.cpp
+++ b/src/keeper.cpp
@@ -72,7 +72,7 @@ static int const CONTENTS_TABLE = 1;
72static keeper_fifo* prepare_fifo_access( lua_State* L, int idx_) 72static keeper_fifo* prepare_fifo_access( lua_State* L, int idx_)
73{ 73{
74 keeper_fifo* fifo = (keeper_fifo*) lua_touserdata( L, idx_); 74 keeper_fifo* fifo = (keeper_fifo*) lua_touserdata( L, idx_);
75 if( fifo != NULL) 75 if( fifo != nullptr)
76 { 76 {
77 idx_ = lua_absindex( L, idx_); 77 idx_ = lua_absindex( L, idx_);
78 STACK_GROW( L, 1); 78 STACK_GROW( L, 1);
@@ -192,8 +192,8 @@ static void push_table( lua_State* L, int idx_)
192int keeper_push_linda_storage( Universe* U, lua_State* L, void* ptr_, ptrdiff_t magic_) 192int keeper_push_linda_storage( Universe* U, lua_State* L, void* ptr_, ptrdiff_t magic_)
193{ 193{
194 Keeper* const K = which_keeper( U->keepers, magic_); 194 Keeper* const K = which_keeper( U->keepers, magic_);
195 lua_State* const KL = K ? K->L : NULL; 195 lua_State* const KL = K ? K->L : nullptr;
196 if( KL == NULL) return 0; 196 if( KL == nullptr) return 0;
197 STACK_GROW( KL, 4); 197 STACK_GROW( KL, 4);
198 STACK_CHECK( KL, 0); 198 STACK_CHECK( KL, 0);
199 REGISTRY_GET( KL, FIFOS_KEY); // fifos 199 REGISTRY_GET( KL, FIFOS_KEY); // fifos
@@ -303,7 +303,7 @@ int keepercall_receive( lua_State* L)
303 lua_pushvalue( L, i); // fifos keys key[i] 303 lua_pushvalue( L, i); // fifos keys key[i]
304 lua_rawget( L, 1); // fifos keys fifo 304 lua_rawget( L, 1); // fifos keys fifo
305 fifo = prepare_fifo_access( L, -1); // fifos keys fifo 305 fifo = prepare_fifo_access( L, -1); // fifos keys fifo
306 if( fifo != NULL && fifo->count > 0) 306 if( fifo != nullptr && fifo->count > 0)
307 { 307 {
308 fifo_pop( L, fifo, 1); // fifos keys val 308 fifo_pop( L, fifo, 1); // fifos keys val
309 if( !lua_isnil( L, -1)) 309 if( !lua_isnil( L, -1))
@@ -341,7 +341,7 @@ int keepercall_receive_batched( lua_State* L)
341 lua_rawget( L, 2); // key fifos fifo 341 lua_rawget( L, 2); // key fifos fifo
342 lua_remove( L, 2); // key fifo 342 lua_remove( L, 2); // key fifo
343 fifo = prepare_fifo_access( L, 2); // key fifo 343 fifo = prepare_fifo_access( L, 2); // key fifo
344 if( fifo != NULL && fifo->count >= min_count) 344 if( fifo != nullptr && fifo->count >= min_count)
345 { 345 {
346 fifo_pop( L, fifo, __min( max_count, fifo->count)); // key ... 346 fifo_pop( L, fifo, __min( max_count, fifo->count)); // key ...
347 } 347 }
@@ -369,7 +369,7 @@ int keepercall_limit( lua_State* L)
369 lua_pushvalue( L, -1); // fifos key key 369 lua_pushvalue( L, -1); // fifos key key
370 lua_rawget( L, -3); // fifos key fifo|nil 370 lua_rawget( L, -3); // fifos key fifo|nil
371 fifo = (keeper_fifo*) lua_touserdata( L, -1); 371 fifo = (keeper_fifo*) lua_touserdata( L, -1);
372 if( fifo == NULL) 372 if( fifo == nullptr)
373 { // fifos key nil 373 { // fifos key nil
374 lua_pop( L, 1); // fifos key 374 lua_pop( L, 1); // fifos key
375 fifo_new( L); // fifos key fifo 375 fifo_new( L); // fifos key fifo
@@ -412,7 +412,7 @@ int keepercall_set( lua_State* L)
412 lua_rawget( L, 1); // fifos key fifo|nil 412 lua_rawget( L, 1); // fifos key fifo|nil
413 // empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged! 413 // empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged!
414 fifo = (keeper_fifo*) lua_touserdata( L, -1); 414 fifo = (keeper_fifo*) lua_touserdata( L, -1);
415 if( fifo != NULL) // might be NULL if we set a nonexistent key to nil 415 if( fifo != nullptr) // might be NULL if we set a nonexistent key to nil
416 { // fifos key fifo 416 { // fifos key fifo
417 if( fifo->limit < 0) // fifo limit value is the default (unlimited): we can totally remove it 417 if( fifo->limit < 0) // fifo limit value is the default (unlimited): we can totally remove it
418 { 418 {
@@ -439,7 +439,7 @@ int keepercall_set( lua_State* L)
439 lua_pushvalue( L, 2); // fifos key [val [, ...]] key 439 lua_pushvalue( L, 2); // fifos key [val [, ...]] key
440 lua_rawget( L, 1); // fifos key [val [, ...]] fifo|nil 440 lua_rawget( L, 1); // fifos key [val [, ...]] fifo|nil
441 fifo = (keeper_fifo*) lua_touserdata( L, -1); 441 fifo = (keeper_fifo*) lua_touserdata( L, -1);
442 if( fifo == NULL) // can be NULL if we store a value at a new key 442 if( fifo == nullptr) // can be nullptr if we store a value at a new key
443 { // fifos key [val [, ...]] nil 443 { // fifos key [val [, ...]] nil
444 // no need to wake writers in that case, because a writer can't wait on an inexistent key 444 // no need to wake writers in that case, because a writer can't wait on an inexistent key
445 lua_pop( L, 1); // fifos key [val [, ...]] 445 lua_pop( L, 1); // fifos key [val [, ...]]
@@ -481,7 +481,7 @@ int keepercall_get( lua_State* L)
481 lua_replace( L, 1); // fifos key 481 lua_replace( L, 1); // fifos key
482 lua_rawget( L, 1); // fifos fifo 482 lua_rawget( L, 1); // fifos fifo
483 fifo = prepare_fifo_access( L, -1); // fifos fifo 483 fifo = prepare_fifo_access( L, -1); // fifos fifo
484 if( fifo != NULL && fifo->count > 0) 484 if( fifo != nullptr && fifo->count > 0)
485 { 485 {
486 lua_remove( L, 1); // fifo 486 lua_remove( L, 1); // fifo
487 count = __min( count, fifo->count); 487 count = __min( count, fifo->count);
@@ -548,7 +548,7 @@ int keepercall_count( lua_State* L)
548 lua_rawget( L, 2); // out fifos keys fifo|nil 548 lua_rawget( L, 2); // out fifos keys fifo|nil
549 fifo = prepare_fifo_access( L, -1); // out fifos keys fifo|nil 549 fifo = prepare_fifo_access( L, -1); // out fifos keys fifo|nil
550 lua_pop( L, 1); // out fifos keys 550 lua_pop( L, 1); // out fifos keys
551 if( fifo != NULL) // the key is known 551 if( fifo != nullptr) // the key is known
552 { 552 {
553 lua_pushinteger( L, fifo->count); // out fifos keys count 553 lua_pushinteger( L, fifo->count); // out fifos keys count
554 lua_rawset( L, 1); // out fifos keys 554 lua_rawset( L, 1); // out fifos keys
@@ -582,7 +582,7 @@ int keepercall_count( lua_State* L)
582// called as __gc for the keepers array userdata 582// called as __gc for the keepers array userdata
583void close_keepers( Universe* U) 583void close_keepers( Universe* U)
584{ 584{
585 if( U->keepers != NULL) 585 if( U->keepers != nullptr)
586 { 586 {
587 int i; 587 int i;
588 int nbKeepers = U->keepers->nb_keepers; 588 int nbKeepers = U->keepers->nb_keepers;
@@ -594,8 +594,8 @@ void close_keepers( Universe* U)
594 for( i = 0; i < nbKeepers; ++ i) 594 for( i = 0; i < nbKeepers; ++ i)
595 { 595 {
596 lua_State* K = U->keepers->keeper_array[i].L; 596 lua_State* K = U->keepers->keeper_array[i].L;
597 U->keepers->keeper_array[i].L = NULL; 597 U->keepers->keeper_array[i].L = nullptr;
598 if( K != NULL) 598 if( K != nullptr)
599 { 599 {
600 lua_close( K); 600 lua_close( K);
601 } 601 }
@@ -613,7 +613,7 @@ void close_keepers( Universe* U)
613 { 613 {
614 AllocatorDefinition* const allocD = &U->internal_allocator; 614 AllocatorDefinition* const allocD = &U->internal_allocator;
615 (void) allocD->allocF( allocD->allocUD, U->keepers, sizeof( Keepers) + (nbKeepers - 1) * sizeof( Keeper), 0); 615 (void) allocD->allocF( allocD->allocUD, U->keepers, sizeof( Keepers) + (nbKeepers - 1) * sizeof( Keeper), 0);
616 U->keepers = NULL; 616 U->keepers = nullptr;
617 } 617 }
618 } 618 }
619} 619}
@@ -648,9 +648,9 @@ void init_keepers( Universe* U, lua_State* L)
648 size_t const bytes = sizeof( Keepers) + (nb_keepers - 1) * sizeof( Keeper); 648 size_t const bytes = sizeof( Keepers) + (nb_keepers - 1) * sizeof( Keeper);
649 { 649 {
650 AllocatorDefinition* const allocD = &U->internal_allocator; 650 AllocatorDefinition* const allocD = &U->internal_allocator;
651 U->keepers = (Keepers*) allocD->allocF( allocD->allocUD, NULL, 0, bytes); 651 U->keepers = (Keepers*) allocD->allocF( allocD->allocUD, nullptr, 0, bytes);
652 } 652 }
653 if( U->keepers == NULL) 653 if( U->keepers == nullptr)
654 { 654 {
655 (void) luaL_error( L, "init_keepers() failed while creating keeper array; out of memory"); 655 (void) luaL_error( L, "init_keepers() failed while creating keeper array; out of memory");
656 return; 656 return;
@@ -662,7 +662,7 @@ void init_keepers( Universe* U, lua_State* L)
662 { 662 {
663 // note that we will leak K if we raise an error later 663 // note that we will leak K if we raise an error later
664 lua_State* K = create_state( U, L); 664 lua_State* K = create_state( U, L);
665 if( K == NULL) 665 if( K == nullptr)
666 { 666 {
667 (void) luaL_error( L, "init_keepers() failed while creating keeper states; out of memory"); 667 (void) luaL_error( L, "init_keepers() failed while creating keeper states; out of memory");
668 return; 668 return;
@@ -734,7 +734,7 @@ Keeper* keeper_acquire( Keepers* keepers_, ptrdiff_t magic_)
734 // can be 0 if this happens during main state shutdown (lanes is being GC'ed -> no keepers) 734 // can be 0 if this happens during main state shutdown (lanes is being GC'ed -> no keepers)
735 if( nbKeepers == 0) 735 if( nbKeepers == 0)
736 { 736 {
737 return NULL; 737 return nullptr;
738 } 738 }
739 else 739 else
740 { 740 {
diff --git a/src/lanes.cpp b/src/lanes.cpp
index deee90c..d97a539 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -176,7 +176,7 @@ static bool_t push_registry_table( lua_State* L, UniqueKey key, bool_t create)
176 176
177#if HAVE_LANE_TRACKING() 177#if HAVE_LANE_TRACKING()
178 178
179// The chain is ended by '(Lane*)(-1)', not NULL: 179// The chain is ended by '(Lane*)(-1)', not nullptr:
180// 'tracking_first -> ... -> ... -> (-1)' 180// 'tracking_first -> ... -> ... -> (-1)'
181#define TRACKING_END ((Lane *)(-1)) 181#define TRACKING_END ((Lane *)(-1))
182 182
@@ -189,7 +189,7 @@ static void tracking_add( Lane* s)
189 189
190 MUTEX_LOCK( &s->U->tracking_cs); 190 MUTEX_LOCK( &s->U->tracking_cs);
191 { 191 {
192 assert( s->tracking_next == NULL); 192 assert( s->tracking_next == nullptr);
193 193
194 s->tracking_next = s->U->tracking_first; 194 s->tracking_next = s->U->tracking_first;
195 s->U->tracking_first = s; 195 s->U->tracking_first = s;
@@ -209,7 +209,7 @@ static bool_t tracking_remove( Lane* s)
209 // still (at process exit they will remove us from chain and then 209 // still (at process exit they will remove us from chain and then
210 // cancel/kill). 210 // cancel/kill).
211 // 211 //
212 if( s->tracking_next != NULL) 212 if( s->tracking_next != nullptr)
213 { 213 {
214 Lane** ref = (Lane**) &s->U->tracking_first; 214 Lane** ref = (Lane**) &s->U->tracking_first;
215 215
@@ -218,7 +218,7 @@ static bool_t tracking_remove( Lane* s)
218 if( *ref == s) 218 if( *ref == s)
219 { 219 {
220 *ref = s->tracking_next; 220 *ref = s->tracking_next;
221 s->tracking_next = NULL; 221 s->tracking_next = nullptr;
222 found = TRUE; 222 found = TRUE;
223 break; 223 break;
224 } 224 }
@@ -246,7 +246,7 @@ static void lane_cleanup( Lane* s)
246#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR 246#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR
247 247
248#if HAVE_LANE_TRACKING() 248#if HAVE_LANE_TRACKING()
249 if( s->U->tracking_first != NULL) 249 if( s->U->tracking_first != nullptr)
250 { 250 {
251 // Lane was cleaned up, no need to handle at process termination 251 // Lane was cleaned up, no need to handle at process termination
252 tracking_remove( s); 252 tracking_remove( s);
@@ -386,7 +386,7 @@ static int run_finalizers( lua_State* L, int lua_rc)
386 386
387#define SELFDESTRUCT_END ((Lane*)(-1)) 387#define SELFDESTRUCT_END ((Lane*)(-1))
388// 388//
389// The chain is ended by '(Lane*)(-1)', not NULL: 389// The chain is ended by '(Lane*)(-1)', not nullptr:
390// 'selfdestruct_first -> ... -> ... -> (-1)' 390// 'selfdestruct_first -> ... -> ... -> (-1)'
391 391
392/* 392/*
@@ -396,7 +396,7 @@ static int run_finalizers( lua_State* L, int lua_rc)
396static void selfdestruct_add( Lane* s) 396static void selfdestruct_add( Lane* s)
397{ 397{
398 MUTEX_LOCK( &s->U->selfdestruct_cs); 398 MUTEX_LOCK( &s->U->selfdestruct_cs);
399 assert( s->selfdestruct_next == NULL); 399 assert( s->selfdestruct_next == nullptr);
400 400
401 s->selfdestruct_next = s->U->selfdestruct_first; 401 s->selfdestruct_next = s->U->selfdestruct_first;
402 s->U->selfdestruct_first= s; 402 s->U->selfdestruct_first= s;
@@ -415,7 +415,7 @@ static bool_t selfdestruct_remove( Lane* s)
415 // still (at process exit they will remove us from chain and then 415 // still (at process exit they will remove us from chain and then
416 // cancel/kill). 416 // cancel/kill).
417 // 417 //
418 if( s->selfdestruct_next != NULL) 418 if( s->selfdestruct_next != nullptr)
419 { 419 {
420 Lane** ref = (Lane**) &s->U->selfdestruct_first; 420 Lane** ref = (Lane**) &s->U->selfdestruct_first;
421 421
@@ -424,7 +424,7 @@ static bool_t selfdestruct_remove( Lane* s)
424 if( *ref == s) 424 if( *ref == s)
425 { 425 {
426 *ref = s->selfdestruct_next; 426 *ref = s->selfdestruct_next;
427 s->selfdestruct_next = NULL; 427 s->selfdestruct_next = nullptr;
428 // the terminal shutdown should wait until the lane is done with its lua_close() 428 // the terminal shutdown should wait until the lane is done with its lua_close()
429 ++ s->U->selfdestructing_count; 429 ++ s->U->selfdestructing_count;
430 found = TRUE; 430 found = TRUE;
@@ -458,12 +458,12 @@ static int selfdestruct_gc( lua_State* L)
458 // attempt a regular unforced hard cancel with a small timeout 458 // attempt a regular unforced hard cancel with a small timeout
459 bool_t cancelled = THREAD_ISNULL( s->thread) || thread_cancel( L, s, CO_Hard, 0.0001, FALSE, 0.0); 459 bool_t cancelled = THREAD_ISNULL( s->thread) || thread_cancel( L, s, CO_Hard, 0.0001, FALSE, 0.0);
460 // if we failed, and we know the thread is waiting on a linda 460 // if we failed, and we know the thread is waiting on a linda
461 if( cancelled == FALSE && s->status == WAITING && s->waiting_on != NULL) 461 if( cancelled == FALSE && s->status == WAITING && s->waiting_on != nullptr)
462 { 462 {
463 // signal the linda to wake up the thread so that it can react to the cancel query 463 // signal the linda to wake up the thread so that it can react to the cancel query
464 // let us hope we never land here with a pointer on a linda that has been destroyed... 464 // let us hope we never land here with a pointer on a linda that has been destroyed...
465 SIGNAL_T* waiting_on = s->waiting_on; 465 SIGNAL_T* waiting_on = s->waiting_on;
466 //s->waiting_on = NULL; // useful, or not? 466 //s->waiting_on = nullptr; // useful, or not?
467 SIGNAL_ALL( waiting_on); 467 SIGNAL_ALL( waiting_on);
468 } 468 }
469 s = s->selfdestruct_next; 469 s = s->selfdestruct_next;
@@ -540,8 +540,8 @@ static int selfdestruct_gc( lua_State* L)
540 while( s != SELFDESTRUCT_END) 540 while( s != SELFDESTRUCT_END)
541 { 541 {
542 Lane* next_s = s->selfdestruct_next; 542 Lane* next_s = s->selfdestruct_next;
543 s->selfdestruct_next = NULL; // detach from selfdestruct chain 543 s->selfdestruct_next = nullptr; // detach from selfdestruct chain
544 if( !THREAD_ISNULL( s->thread)) // can be NULL if previous 'soft' termination succeeded 544 if( !THREAD_ISNULL( s->thread)) // can be nullptr if previous 'soft' termination succeeded
545 { 545 {
546 THREAD_KILL( &s->thread); 546 THREAD_KILL( &s->thread);
547#if THREADAPI == THREADAPI_PTHREAD 547#if THREADAPI == THREADAPI_PTHREAD
@@ -572,11 +572,11 @@ static int selfdestruct_gc( lua_State* L)
572 // necessary so that calling free_deep_prelude doesn't crash because linda_id expects a linda lightuserdata at absolute slot 1 572 // necessary so that calling free_deep_prelude doesn't crash because linda_id expects a linda lightuserdata at absolute slot 1
573 lua_settop( L, 0); 573 lua_settop( L, 0);
574 // no need to mutex-protect this as all threads in the universe are gone at that point 574 // no need to mutex-protect this as all threads in the universe are gone at that point
575 if( U->timer_deep != NULL) // test ins case some early internal error prevented Lanes from creating the deep timer 575 if( U->timer_deep != nullptr) // test ins case some early internal error prevented Lanes from creating the deep timer
576 { 576 {
577 -- U->timer_deep->refcount; // should be 0 now 577 -- U->timer_deep->refcount; // should be 0 now
578 free_deep_prelude( L, (DeepPrelude*) U->timer_deep); 578 free_deep_prelude( L, (DeepPrelude*) U->timer_deep);
579 U->timer_deep = NULL; 579 U->timer_deep = nullptr;
580 } 580 }
581 581
582 close_keepers( U); 582 close_keepers( U);
@@ -596,7 +596,7 @@ static int selfdestruct_gc( lua_State* L)
596 // universe is no longer available (nor necessary) 596 // universe is no longer available (nor necessary)
597 // we need to do this in case some deep userdata objects were created before Lanes was initialized, 597 // we need to do this in case some deep userdata objects were created before Lanes was initialized,
598 // as potentially they will be garbage collected after Lanes at application shutdown 598 // as potentially they will be garbage collected after Lanes at application shutdown
599 universe_store( L, NULL); 599 universe_store( L, nullptr);
600 return 0; 600 return 0;
601} 601}
602 602
@@ -868,7 +868,7 @@ static char const* get_errcode_name( int _code)
868 return s_errcodes[i].name; 868 return s_errcodes[i].name;
869 } 869 }
870 } 870 }
871 return "<NULL>"; 871 return "<nullptr>";
872} 872}
873#endif // USE_DEBUG_SPEW() 873#endif // USE_DEBUG_SPEW()
874 874
@@ -943,7 +943,7 @@ static THREAD_RETURN_T THREAD_CALLCONV lane_main( void* vs)
943 // the finalizer generated an error, and left its own error message [and stack trace] on the stack 943 // the finalizer generated an error, and left its own error message [and stack trace] on the stack
944 rc = rc2; // we're overruling the earlier script error or normal return 944 rc = rc2; // we're overruling the earlier script error or normal return
945 } 945 }
946 s->waiting_on = NULL; // just in case 946 s->waiting_on = nullptr; // just in case
947 if( selfdestruct_remove( s)) // check and remove (under lock!) 947 if( selfdestruct_remove( s)) // check and remove (under lock!)
948 { 948 {
949 // We're a free-running thread and no-one's there to clean us up. 949 // We're a free-running thread and no-one's there to clean us up.
@@ -1228,9 +1228,9 @@ LUAG_FUNC( lane_new)
1228 ud = (Lane**) lua_newuserdatauv( L, sizeof( Lane*), 1); // func libs priority globals package required gc_cb lane 1228 ud = (Lane**) lua_newuserdatauv( L, sizeof( Lane*), 1); // func libs priority globals package required gc_cb lane
1229 { 1229 {
1230 AllocatorDefinition* const allocD = &U->internal_allocator; 1230 AllocatorDefinition* const allocD = &U->internal_allocator;
1231 s = *ud = (Lane*) allocD->allocF(allocD->allocUD, NULL, 0, sizeof(Lane)); 1231 s = *ud = (Lane*) allocD->allocF(allocD->allocUD, nullptr, 0, sizeof(Lane));
1232 } 1232 }
1233 if( s == NULL) 1233 if( s == nullptr)
1234 { 1234 {
1235 return luaL_error( L, "could not create lane: out of memory"); 1235 return luaL_error( L, "could not create lane: out of memory");
1236 } 1236 }
@@ -1238,7 +1238,7 @@ LUAG_FUNC( lane_new)
1238 s->L = L2; 1238 s->L = L2;
1239 s->U = U; 1239 s->U = U;
1240 s->status = PENDING; 1240 s->status = PENDING;
1241 s->waiting_on = NULL; 1241 s->waiting_on = nullptr;
1242 s->debug_name = "<unnamed>"; 1242 s->debug_name = "<unnamed>";
1243 s->cancel_request = CANCEL_NONE; 1243 s->cancel_request = CANCEL_NONE;
1244 1244
@@ -1247,9 +1247,9 @@ LUAG_FUNC( lane_new)
1247 SIGNAL_INIT( &s->done_signal); 1247 SIGNAL_INIT( &s->done_signal);
1248#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR 1248#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR
1249 s->mstatus = NORMAL; 1249 s->mstatus = NORMAL;
1250 s->selfdestruct_next = NULL; 1250 s->selfdestruct_next = nullptr;
1251#if HAVE_LANE_TRACKING() 1251#if HAVE_LANE_TRACKING()
1252 s->tracking_next = NULL; 1252 s->tracking_next = nullptr;
1253 if( s->U->tracking_first) 1253 if( s->U->tracking_first)
1254 { 1254 {
1255 tracking_add( s); 1255 tracking_add( s);
@@ -1399,7 +1399,7 @@ static char const * thread_status_string( Lane* s)
1399 (st == WAITING) ? "waiting" : 1399 (st == WAITING) ? "waiting" :
1400 (st == DONE) ? "done" : 1400 (st == DONE) ? "done" :
1401 (st == ERROR_ST) ? "error" : 1401 (st == ERROR_ST) ? "error" :
1402 (st == CANCELLED) ? "cancelled" : NULL; 1402 (st == CANCELLED) ? "cancelled" : nullptr;
1403 return str; 1403 return str;
1404} 1404}
1405 1405
@@ -1767,7 +1767,7 @@ static const struct luaL_Reg lanes_functions [] = {
1767 {"nameof", luaG_nameof}, 1767 {"nameof", luaG_nameof},
1768 {"register", LG_register}, 1768 {"register", LG_register},
1769 {"set_singlethreaded", LG_set_singlethreaded}, 1769 {"set_singlethreaded", LG_set_singlethreaded},
1770 {NULL, NULL} 1770 {nullptr, nullptr}
1771}; 1771};
1772 1772
1773/* 1773/*
@@ -1820,7 +1820,7 @@ static volatile long s_initCount = 0;
1820LUAG_FUNC( configure) 1820LUAG_FUNC( configure)
1821{ 1821{
1822 Universe* U = universe_get( L); 1822 Universe* U = universe_get( L);
1823 bool_t const from_master_state = (U == NULL); 1823 bool_t const from_master_state = (U == nullptr);
1824 char const* name = luaL_checkstring( L, lua_upvalueindex( 1)); 1824 char const* name = luaL_checkstring( L, lua_upvalueindex( 1));
1825 _ASSERT_L( L, lua_type( L, 1) == LUA_TTABLE); 1825 _ASSERT_L( L, lua_type( L, 1) == LUA_TTABLE);
1826 1826
@@ -1868,7 +1868,7 @@ LUAG_FUNC( configure)
1868 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() BEGIN\n" INDENT_END, L)); 1868 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() BEGIN\n" INDENT_END, L));
1869 DEBUGSPEW_CODE( if( U) ++ U->debugspew_indent_depth); 1869 DEBUGSPEW_CODE( if( U) ++ U->debugspew_indent_depth);
1870 1870
1871 if( U == NULL) 1871 if( U == nullptr)
1872 { 1872 {
1873 U = universe_create( L); // settings universe 1873 U = universe_create( L); // settings universe
1874 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 1874 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
@@ -1887,7 +1887,7 @@ LUAG_FUNC( configure)
1887#if HAVE_LANE_TRACKING() 1887#if HAVE_LANE_TRACKING()
1888 MUTEX_INIT( &U->tracking_cs); 1888 MUTEX_INIT( &U->tracking_cs);
1889 lua_getfield( L, 1, "track_lanes"); // settings track_lanes 1889 lua_getfield( L, 1, "track_lanes"); // settings track_lanes
1890 U->tracking_first = lua_toboolean( L, -1) ? TRACKING_END : NULL; 1890 U->tracking_first = lua_toboolean( L, -1) ? TRACKING_END : nullptr;
1891 lua_pop( L, 1); // settings 1891 lua_pop( L, 1); // settings
1892#endif // HAVE_LANE_TRACKING() 1892#endif // HAVE_LANE_TRACKING()
1893 // Linked chains handling 1893 // Linked chains handling
@@ -1928,7 +1928,7 @@ LUAG_FUNC( configure)
1928 luaG_registerlibfuncs( L, lanes_functions); 1928 luaG_registerlibfuncs( L, lanes_functions);
1929#if HAVE_LANE_TRACKING() 1929#if HAVE_LANE_TRACKING()
1930 // register core.threads() only if settings say it should be available 1930 // register core.threads() only if settings say it should be available
1931 if( U->tracking_first != NULL) 1931 if( U->tracking_first != nullptr)
1932 { 1932 {
1933 lua_pushcfunction( L, LG_threads); // settings M LG_threads() 1933 lua_pushcfunction( L, LG_threads); // settings M LG_threads()
1934 lua_setfield( L, -2, "threads"); // settings M 1934 lua_setfield( L, -2, "threads"); // settings M
@@ -1939,7 +1939,7 @@ LUAG_FUNC( configure)
1939 { 1939 {
1940 char const* errmsg; 1940 char const* errmsg;
1941 errmsg = push_deep_proxy( U, L, (DeepPrelude*) U->timer_deep, 0, eLM_LaneBody); // settings M timer_deep 1941 errmsg = push_deep_proxy( U, L, (DeepPrelude*) U->timer_deep, 0, eLM_LaneBody); // settings M timer_deep
1942 if( errmsg != NULL) 1942 if( errmsg != nullptr)
1943 { 1943 {
1944 return luaL_error( L, errmsg); 1944 return luaL_error( L, errmsg);
1945 } 1945 }
@@ -2011,7 +2011,7 @@ LUAG_FUNC( configure)
2011 // because we will do it after on_state_create() is called, 2011 // because we will do it after on_state_create() is called,
2012 // and we don't want to skip _G because of caching in case globals are created then 2012 // and we don't want to skip _G because of caching in case globals are created then
2013 lua_pushglobaltable( L); // settings M _G 2013 lua_pushglobaltable( L); // settings M _G
2014 populate_func_lookup_table( L, -1, NULL); 2014 populate_func_lookup_table( L, -1, nullptr);
2015 lua_pop( L, 1); // settings M 2015 lua_pop( L, 1); // settings M
2016 } 2016 }
2017 lua_pop( L, 1); // settings 2017 lua_pop( L, 1); // settings
diff --git a/src/lanes_private.h b/src/lanes_private.h
index 67c99f7..f0d01ac 100644
--- a/src/lanes_private.h
+++ b/src/lanes_private.h
@@ -35,7 +35,7 @@ struct s_Lane
35 35
36 SIGNAL_T* volatile waiting_on; 36 SIGNAL_T* volatile waiting_on;
37 // 37 //
38 // When status is WAITING, points on the linda's signal the thread waits on, else NULL 38 // When status is WAITING, points on the linda's signal the thread waits on, else nullptr
39 39
40 volatile enum e_cancel_request cancel_request; 40 volatile enum e_cancel_request cancel_request;
41 // 41 //
@@ -61,9 +61,9 @@ struct s_Lane
61 61
62 struct s_Lane* volatile selfdestruct_next; 62 struct s_Lane* volatile selfdestruct_next;
63 // 63 //
64 // M: sets to non-NULL if facing lane handle '__gc' cycle but the lane 64 // M: sets to non-nullptr if facing lane handle '__gc' cycle but the lane
65 // is still running 65 // is still running
66 // S: cleans up after itself if non-NULL at lane exit 66 // S: cleans up after itself if non-nullptr at lane exit
67 67
68#if HAVE_LANE_TRACKING() 68#if HAVE_LANE_TRACKING()
69 struct s_Lane* volatile tracking_next; 69 struct s_Lane* volatile tracking_next;
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}
diff --git a/src/universe.cpp b/src/universe.cpp
index 0a014f7..d5cc9e2 100644
--- a/src/universe.cpp
+++ b/src/universe.cpp
@@ -56,7 +56,7 @@ Universe* universe_create( lua_State* L)
56void universe_store( lua_State* L, Universe* U) 56void universe_store( lua_State* L, Universe* U)
57{ 57{
58 STACK_CHECK( L, 0); 58 STACK_CHECK( L, 0);
59 REGISTRY_SET( L, UNIVERSE_REGKEY, (NULL != U) ? lua_pushlightuserdata( L, U) : lua_pushnil( L)); 59 REGISTRY_SET( L, UNIVERSE_REGKEY, (nullptr != U) ? lua_pushlightuserdata( L, U) : lua_pushnil( L));
60 STACK_END( L, 0); 60 STACK_END( L, 0);
61} 61}
62 62