aboutsummaryrefslogtreecommitdiff
path: root/src/keeper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/keeper.c')
-rw-r--r--src/keeper.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/keeper.c b/src/keeper.c
index 516fe85..7485110 100644
--- a/src/keeper.c
+++ b/src/keeper.c
@@ -163,7 +163,7 @@ static void* const fifos_key = (void*) prepare_fifo_access;
163static void push_table( lua_State* L, int idx) 163static void push_table( lua_State* L, int idx)
164{ 164{
165 STACK_GROW( L, 4); 165 STACK_GROW( L, 4);
166 STACK_CHECK( L) 166 STACK_CHECK( L);
167 idx = lua_absindex( L, idx); 167 idx = lua_absindex( L, idx);
168 lua_pushlightuserdata( L, fifos_key); // ud fifos_key 168 lua_pushlightuserdata( L, fifos_key); // ud fifos_key
169 lua_rawget( L, LUA_REGISTRYINDEX); // ud fifos 169 lua_rawget( L, LUA_REGISTRYINDEX); // ud fifos
@@ -187,7 +187,7 @@ int keeper_push_linda_storage( lua_State* L, void* ptr)
187{ 187{
188 struct s_Keeper* K = keeper_acquire( ptr); 188 struct s_Keeper* K = keeper_acquire( ptr);
189 lua_State* KL = K->L; 189 lua_State* KL = K->L;
190 STACK_CHECK( KL) 190 STACK_CHECK( KL);
191 lua_pushlightuserdata( KL, fifos_key); // fifos_key 191 lua_pushlightuserdata( KL, fifos_key); // fifos_key
192 lua_rawget( KL, LUA_REGISTRYINDEX); // fifos 192 lua_rawget( KL, LUA_REGISTRYINDEX); // fifos
193 lua_pushlightuserdata( KL, ptr); // fifos ud 193 lua_pushlightuserdata( KL, ptr); // fifos ud
@@ -206,7 +206,7 @@ int keeper_push_linda_storage( lua_State* L, void* ptr)
206 keeper_fifo* fifo = prepare_fifo_access( KL, -1); // storage key fifo 206 keeper_fifo* fifo = prepare_fifo_access( KL, -1); // storage key fifo
207 lua_pushvalue( KL, -2); // storage key fifo key 207 lua_pushvalue( KL, -2); // storage key fifo key
208 luaG_inter_move( KL, L, 1); // storage key fifo // out key 208 luaG_inter_move( KL, L, 1); // storage key fifo // out key
209 STACK_CHECK( L) 209 STACK_CHECK( L);
210 lua_newtable( L); // out key keyout 210 lua_newtable( L); // out key keyout
211 luaG_inter_move( KL, L, 1); // storage key // out key keyout fifo 211 luaG_inter_move( KL, L, 1); // storage key // out key keyout fifo
212 lua_pushinteger( L, fifo->first); // out key keyout fifo first 212 lua_pushinteger( L, fifo->first); // out key keyout fifo first
@@ -217,10 +217,10 @@ int keeper_push_linda_storage( lua_State* L, void* ptr)
217 lua_setfield( L, -3, "limit"); // out key keyout fifo 217 lua_setfield( L, -3, "limit"); // out key keyout fifo
218 lua_setfield( L, -2, "fifo"); // out key keyout 218 lua_setfield( L, -2, "fifo"); // out key keyout
219 lua_rawset( L, -3); // out 219 lua_rawset( L, -3); // out
220 STACK_END( L, 0) 220 STACK_END( L, 0);
221 } 221 }
222 lua_pop( KL, 1); // 222 lua_pop( KL, 1); //
223 STACK_END( KL, 0) 223 STACK_END( KL, 0);
224 keeper_release( K); 224 keeper_release( K);
225 return 1; 225 return 1;
226} 226}
@@ -565,26 +565,31 @@ char const* init_keepers( lua_State* L, int const _nbKeepers, lua_CFunction _on_
565 GKeepers = malloc( _nbKeepers * sizeof( struct s_Keeper)); 565 GKeepers = malloc( _nbKeepers * sizeof( struct s_Keeper));
566 for( i = 0; i < _nbKeepers; ++ i) 566 for( i = 0; i < _nbKeepers; ++ i)
567 { 567 {
568 lua_State* K;
569 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "### init_keepers %d BEGIN\n" INDENT_END, i));
570 DEBUGSPEW_CODE( ++ debugspew_indent_depth);
568 // We need to load all base libraries in the keeper states so that the transfer databases are populated properly 571 // We need to load all base libraries in the keeper states so that the transfer databases are populated properly
569 // 572 //
570 // 'io' for debugging messages, 'package' because we need to require modules exporting idfuncs 573 // 'io' for debugging messages, 'package' because we need to require modules exporting idfuncs
571 // the others because they export functions that we may store in a keeper for transfer between lanes 574 // the others because they export functions that we may store in a keeper for transfer between lanes
572 lua_State* K = luaG_newstate( L, "*", _on_state_create); 575 K = luaG_newstate( L, "*", _on_state_create);
573 576
574 DEBUGSPEW_CODE( fprintf( stderr, "init_keepers %d\n", i)); 577 STACK_CHECK( K);
578
579 // replace default 'package' contents with stuff gotten from the master state
580 lua_getglobal( L, "package");
581 luaG_inter_copy_package( L, K, -1);
582 lua_pop( L, 1);
583
584 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "### init_keepers %d END\n" INDENT_END, i));
585 DEBUGSPEW_CODE( -- debugspew_indent_depth);
575 586
576 STACK_CHECK( K)
577 // to see VM name in Decoda debugger 587 // to see VM name in Decoda debugger
578 lua_pushliteral( K, "Keeper #"); 588 lua_pushliteral( K, "Keeper #");
579 lua_pushinteger( K, i + 1); 589 lua_pushinteger( K, i + 1);
580 lua_concat( K, 2); 590 lua_concat( K, 2);
581 lua_setglobal( K, "decoda_name"); 591 lua_setglobal( K, "decoda_name");
582 592
583 // replace default 'package' contents with stuff gotten from the master state
584 lua_getglobal( L, "package");
585 luaG_inter_copy_package( L, K, -1);
586 lua_pop( L, 1);
587
588#if KEEPER_MODEL == KEEPER_MODEL_C 593#if KEEPER_MODEL == KEEPER_MODEL_C
589 // create the fifos table in the keeper state 594 // create the fifos table in the keeper state
590 lua_pushlightuserdata( K, fifos_key); 595 lua_pushlightuserdata( K, fifos_key);
@@ -611,7 +616,7 @@ char const* init_keepers( lua_State* L, int const _nbKeepers, lua_CFunction _on_
611 STACK_MID( K, 2); 616 STACK_MID( K, 2);
612 lua_pop( K, 2); 617 lua_pop( K, 2);
613#endif // KEEPER_MODEL == KEEPER_MODEL_LUA 618#endif // KEEPER_MODEL == KEEPER_MODEL_LUA
614 STACK_END( K, 0) 619 STACK_END( K, 0);
615 MUTEX_INIT( &GKeepers[i].lock_); 620 MUTEX_INIT( &GKeepers[i].lock_);
616 GKeepers[i].L = K; 621 GKeepers[i].L = K;
617 //GKeepers[i].count = 0; 622 //GKeepers[i].count = 0;
@@ -630,7 +635,7 @@ void populate_keepers( lua_State* L)
630 char const* name = luaL_checklstring( L, -1, &name_len); 635 char const* name = luaL_checklstring( L, -1, &name_len);
631 int i; 636 int i;
632 637
633 STACK_CHECK( L) 638 STACK_CHECK( L);
634 STACK_GROW( L, 3); 639 STACK_GROW( L, 3);
635 640
636 for( i = 0; i < GNbKeepers; ++ i) 641 for( i = 0; i < GNbKeepers; ++ i)
@@ -638,20 +643,20 @@ void populate_keepers( lua_State* L)
638 lua_State* K = GKeepers[i].L; 643 lua_State* K = GKeepers[i].L;
639 int res; 644 int res;
640 MUTEX_LOCK( &GKeepers[i].lock_); 645 MUTEX_LOCK( &GKeepers[i].lock_);
641 STACK_CHECK( K) 646 STACK_CHECK( K);
642 STACK_GROW( K, 2); 647 STACK_GROW( K, 2);
643 lua_getglobal( K, "require"); 648 lua_getglobal( K, "require");
644 lua_pushlstring( K, name, name_len); 649 lua_pushlstring( K, name, name_len);
645 res = lua_pcall( K, 1, 0, 0); 650 res = lua_pcall( K, 1, 0, 0);
646 if( res != 0) 651 if( res != LUA_OK)
647 { 652 {
648 char const* err = luaL_checkstring( K, -1); 653 char const* err = luaL_checkstring( K, -1);
649 luaL_error( L, "error requiring '%s' in keeper state: %s", name, err); 654 luaL_error( L, "error requiring '%s' in keeper state: %s", name, err);
650 } 655 }
651 STACK_END( K, 0) 656 STACK_END( K, 0);
652 MUTEX_UNLOCK( &GKeepers[i].lock_); 657 MUTEX_UNLOCK( &GKeepers[i].lock_);
653 } 658 }
654 STACK_END( L, 0) 659 STACK_END( L, 0);
655} 660}
656 661
657struct s_Keeper* keeper_acquire( void const* ptr) 662struct s_Keeper* keeper_acquire( void const* ptr)