aboutsummaryrefslogtreecommitdiff
path: root/src/keeper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/keeper.c')
-rw-r--r--src/keeper.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/keeper.c b/src/keeper.c
index dbf083f..94cf8d6 100644
--- a/src/keeper.c
+++ b/src/keeper.c
@@ -42,12 +42,12 @@
42#include <stdio.h> 42#include <stdio.h>
43#include <stdlib.h> 43#include <stdlib.h>
44#include <ctype.h> 44#include <ctype.h>
45#include <assert.h>
45 46
46#include "threading.h" 47#include "keeper.h"
47#include "compat.h" 48#include "compat.h"
48#include "tools.h" 49#include "tools.h"
49#include "universe.h" 50#include "universe.h"
50#include "keeper.h"
51 51
52//################################################################################### 52//###################################################################################
53// Keeper implementation 53// Keeper implementation
@@ -184,9 +184,9 @@ static void push_table( lua_State* L, int idx_)
184 STACK_END( L, 1); 184 STACK_END( L, 1);
185} 185}
186 186
187int keeper_push_linda_storage( struct s_Universe* U, lua_State* L, void* ptr_, ptrdiff_t magic_) 187int keeper_push_linda_storage( Universe* U, lua_State* L, void* ptr_, ptrdiff_t magic_)
188{ 188{
189 struct s_Keeper* const K = keeper_acquire( U->keepers, magic_); 189 Keeper* const K = keeper_acquire( U->keepers, magic_);
190 lua_State* const KL = K ? K->L : NULL; 190 lua_State* const KL = K ? K->L : NULL;
191 if( KL == NULL) return 0; 191 if( KL == NULL) return 0;
192 STACK_GROW( KL, 4); 192 STACK_GROW( KL, 4);
@@ -576,7 +576,7 @@ int keepercall_count( lua_State* L)
576*/ 576*/
577 577
578// called as __gc for the keepers array userdata 578// called as __gc for the keepers array userdata
579void close_keepers( struct s_Universe* U, lua_State* L) 579void close_keepers( Universe* U, lua_State* L)
580{ 580{
581 if( U->keepers != NULL) 581 if( U->keepers != NULL)
582 { 582 {
@@ -609,7 +609,7 @@ void close_keepers( struct s_Universe* U, lua_State* L)
609 { 609 {
610 void* allocUD; 610 void* allocUD;
611 lua_Alloc allocF = lua_getallocf( L, &allocUD); 611 lua_Alloc allocF = lua_getallocf( L, &allocUD);
612 allocF( allocUD, U->keepers, sizeof( struct s_Keepers) + (nbKeepers - 1) * sizeof(struct s_Keeper), 0); 612 allocF( allocUD, U->keepers, sizeof( Keepers) + (nbKeepers - 1) * sizeof( Keeper), 0);
613 U->keepers = NULL; 613 U->keepers = NULL;
614 } 614 }
615 } 615 }
@@ -626,7 +626,7 @@ void close_keepers( struct s_Universe* U, lua_State* L)
626 * function never fails. 626 * function never fails.
627 * settings table is at position 1 on the stack 627 * settings table is at position 1 on the stack
628 */ 628 */
629void init_keepers( struct s_Universe* U, lua_State* L) 629void init_keepers( Universe* U, lua_State* L)
630{ 630{
631 int i; 631 int i;
632 int nb_keepers; 632 int nb_keepers;
@@ -639,10 +639,10 @@ void init_keepers( struct s_Universe* U, lua_State* L)
639 lua_pop( L, 1); // 639 lua_pop( L, 1); //
640 assert( nb_keepers >= 1); 640 assert( nb_keepers >= 1);
641 641
642 // struct s_Keepers contains an array of 1 s_Keeper, adjust for the actual number of keeper states 642 // Keepers contains an array of 1 s_Keeper, adjust for the actual number of keeper states
643 { 643 {
644 size_t const bytes = sizeof( struct s_Keepers) + (nb_keepers - 1) * sizeof(struct s_Keeper); 644 size_t const bytes = sizeof( Keepers) + (nb_keepers - 1) * sizeof( Keeper);
645 U->keepers = (struct s_Keepers*) allocF( allocUD, NULL, 0, bytes); 645 U->keepers = (Keepers*) allocF( allocUD, NULL, 0, bytes);
646 if( U->keepers == NULL) 646 if( U->keepers == NULL)
647 { 647 {
648 (void) luaL_error( L, "init_keepers() failed while creating keeper array; out of memory"); 648 (void) luaL_error( L, "init_keepers() failed while creating keeper array; out of memory");
@@ -713,7 +713,7 @@ void init_keepers( struct s_Universe* U, lua_State* L)
713 STACK_END( L, 0); 713 STACK_END( L, 0);
714} 714}
715 715
716struct s_Keeper* keeper_acquire( struct s_Keepers* keepers_, ptrdiff_t magic_) 716Keeper* keeper_acquire( Keepers* keepers_, ptrdiff_t magic_)
717{ 717{
718 int const nbKeepers = keepers_->nb_keepers; 718 int const nbKeepers = keepers_->nb_keepers;
719 // can be 0 if this happens during main state shutdown (lanes is being GC'ed -> no keepers) 719 // can be 0 if this happens during main state shutdown (lanes is being GC'ed -> no keepers)
@@ -731,7 +731,7 @@ struct s_Keeper* keeper_acquire( struct s_Keepers* keepers_, ptrdiff_t magic_)
731 * have to cast to unsigned long to avoid compilation warnings about loss of data when converting pointer-to-integer 731 * have to cast to unsigned long to avoid compilation warnings about loss of data when converting pointer-to-integer
732 */ 732 */
733 unsigned int i = (unsigned int)((magic_ >> KEEPER_MAGIC_SHIFT) % nbKeepers); 733 unsigned int i = (unsigned int)((magic_ >> KEEPER_MAGIC_SHIFT) % nbKeepers);
734 struct s_Keeper* K = &keepers_->keeper_array[i]; 734 Keeper* K = &keepers_->keeper_array[i];
735 735
736 MUTEX_LOCK( &K->keeper_cs); 736 MUTEX_LOCK( &K->keeper_cs);
737 //++ K->count; 737 //++ K->count;
@@ -739,7 +739,7 @@ struct s_Keeper* keeper_acquire( struct s_Keepers* keepers_, ptrdiff_t magic_)
739 } 739 }
740} 740}
741 741
742void keeper_release( struct s_Keeper* K) 742void keeper_release( Keeper* K)
743{ 743{
744 //-- K->count; 744 //-- K->count;
745 if( K) MUTEX_UNLOCK( &K->keeper_cs); 745 if( K) MUTEX_UNLOCK( &K->keeper_cs);
@@ -778,7 +778,7 @@ void keeper_toggle_nil_sentinels( lua_State* L, int val_i_, enum eLookupMode mod
778* 778*
779* Returns: number of return values (pushed to 'L') or -1 in case of error 779* Returns: number of return values (pushed to 'L') or -1 in case of error
780*/ 780*/
781int keeper_call( struct s_Universe* U, lua_State* K, keeper_api_t func_, lua_State* L, void* linda, uint_t starting_index) 781int keeper_call( Universe* U, lua_State* K, keeper_api_t func_, lua_State* L, void* linda, uint_t starting_index)
782{ 782{
783 int const args = starting_index ? (lua_gettop( L) - starting_index + 1) : 0; 783 int const args = starting_index ? (lua_gettop( L) - starting_index + 1) : 0;
784 int const Ktos = lua_gettop( K); 784 int const Ktos = lua_gettop( K);