aboutsummaryrefslogtreecommitdiff
path: root/src/keeper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/keeper.cpp')
-rw-r--r--src/keeper.cpp36
1 files changed, 18 insertions, 18 deletions
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 {