aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.c
diff options
context:
space:
mode:
authorBenoit Germain <b n t DOT g e r m a i n AT g m a i l DOT c o m>2013-09-26 21:11:24 +0200
committerBenoit Germain <b n t DOT g e r m a i n AT g m a i l DOT c o m>2013-09-26 21:11:24 +0200
commitf823c6887e28c815234f8b4bd355887b4f554857 (patch)
tree862b37cc93d6779c3c2577e78ed6ff5389412f90 /src/lanes.c
parentc97ad8630ea9dcb92b4e9db16c4dbade1de18884 (diff)
downloadlanes-f823c6887e28c815234f8b4bd355887b4f554857.tar.gz
lanes-f823c6887e28c815234f8b4bd355887b4f554857.tar.bz2
lanes-f823c6887e28c815234f8b4bd355887b4f554857.zip
Reduce memory footprint, simplify module order setup in conjuction with Lanes, and send over native functions a bit faster as well
* Lanes no longer has to internally require modules inside the keeper states because they no longer need a lookup database. the lookup name is stored as-is and actually converted in the destination state * optimisation: bypass cache when sending native functions over * removed all the KEEPER_MODEL_LUA code, as it can no longer work anyway
Diffstat (limited to 'src/lanes.c')
-rw-r--r--src/lanes.c43
1 files changed, 11 insertions, 32 deletions
diff --git a/src/lanes.c b/src/lanes.c
index 7eef2d0..dc1eeed 100644
--- a/src/lanes.c
+++ b/src/lanes.c
@@ -52,7 +52,7 @@
52 * ... 52 * ...
53 */ 53 */
54 54
55char const* VERSION = "3.6.4"; 55char const* VERSION = "3.6.5";
56 56
57/* 57/*
58=============================================================================== 58===============================================================================
@@ -1862,23 +1862,23 @@ static THREAD_RETURN_T THREAD_CALLCONV lane_main( void *vs)
1862} 1862}
1863 1863
1864// --- If a client wants to transfer stuff of a given module from the current state to another Lane, the module must be required 1864// --- If a client wants to transfer stuff of a given module from the current state to another Lane, the module must be required
1865// with lanes.require, that will call the regular 'require', then populate lookup databases in source and keeper states 1865// with lanes.require, that will call the regular 'require', then populate the lookup database in the source lane
1866// module = lanes.require( "modname") 1866// module = lanes.require( "modname")
1867// upvalue[1]: _G.require 1867// upvalue[1]: _G.require
1868LUAG_FUNC( require) 1868LUAG_FUNC( require)
1869{ 1869{
1870 char const* name = lua_tostring( L, 1); 1870 char const* name = lua_tostring( L, 1);
1871 STACK_CHECK( L);
1871 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.require %s BEGIN\n" INDENT_END, name)); 1872 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.require %s BEGIN\n" INDENT_END, name));
1872 DEBUGSPEW_CODE( ++ debugspew_indent_depth); 1873 DEBUGSPEW_CODE( ++ debugspew_indent_depth);
1873 lua_pushvalue( L, lua_upvalueindex(1)); // "name" require 1874 lua_pushvalue( L, lua_upvalueindex(1)); // "name" require
1874 lua_pushvalue( L, 1); // "name" require "name" 1875 lua_pushvalue( L, 1); // "name" require "name"
1875 lua_call( L, 1, 1); // "name" module 1876 lua_call( L, 1, 1); // "name" module
1876 populate_func_lookup_table( L, -1, name); 1877 populate_func_lookup_table( L, -1, name);
1877 lua_insert( L, -2); // module "name" 1878 lua_remove( L, -2); // module
1878 populate_keepers( L);
1879 lua_pop( L, 1); // module
1880 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.require %s END\n" INDENT_END, name)); 1879 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.require %s END\n" INDENT_END, name));
1881 DEBUGSPEW_CODE( -- debugspew_indent_depth); 1880 DEBUGSPEW_CODE( -- debugspew_indent_depth);
1881 STACK_END( L, 1);
1882 return 1; 1882 return 1;
1883} 1883}
1884 1884
@@ -1937,7 +1937,7 @@ LUAG_FUNC( thread_new)
1937 // package 1937 // package
1938 if( package) 1938 if( package)
1939 { 1939 {
1940 luaG_inter_copy_package( L, L2, package); 1940 luaG_inter_copy_package( L, L2, package, eLM_LaneBody);
1941 } 1941 }
1942 1942
1943 // modules to require in the target lane *before* the function is transfered! 1943 // modules to require in the target lane *before* the function is transfered!
@@ -1986,8 +1986,6 @@ LUAG_FUNC( thread_new)
1986 populate_func_lookup_table( L2, -1, name); 1986 populate_func_lookup_table( L2, -1, name);
1987 STACK_MID( L2, 1); 1987 STACK_MID( L2, 1);
1988 lua_pop( L2, 1); 1988 lua_pop( L2, 1);
1989 // don't require this module in the keeper states as well, use lanes.require() for that!
1990 //populate_keepers( L);
1991 } 1989 }
1992 STACK_END( L2, 0); 1990 STACK_END( L2, 0);
1993 } 1991 }
@@ -2017,7 +2015,7 @@ LUAG_FUNC( thread_new)
2017 lua_pushglobaltable( L2); // Lua 5.2 wants us to push the globals table on the stack 2015 lua_pushglobaltable( L2); // Lua 5.2 wants us to push the globals table on the stack
2018 while( lua_next( L, glob)) 2016 while( lua_next( L, glob))
2019 { 2017 {
2020 luaG_inter_copy( L, L2, 2); // moves the key/value pair to the L2 stack 2018 luaG_inter_copy( L, L2, 2, eLM_LaneBody); // moves the key/value pair to the L2 stack
2021 // assign it in L2's globals table 2019 // assign it in L2's globals table
2022 lua_rawset( L2, -3); 2020 lua_rawset( L2, -3);
2023 lua_pop( L, 1); 2021 lua_pop( L, 1);
@@ -2040,7 +2038,7 @@ LUAG_FUNC( thread_new)
2040 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "thread_new: transfer lane body\n" INDENT_END)); 2038 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "thread_new: transfer lane body\n" INDENT_END));
2041 DEBUGSPEW_CODE( ++ debugspew_indent_depth); 2039 DEBUGSPEW_CODE( ++ debugspew_indent_depth);
2042 lua_pushvalue( L, 1); 2040 lua_pushvalue( L, 1);
2043 res = luaG_inter_move( L, L2, 1); // L->L2 2041 res = luaG_inter_move( L, L2, 1, eLM_LaneBody); // L->L2
2044 DEBUGSPEW_CODE( -- debugspew_indent_depth); 2042 DEBUGSPEW_CODE( -- debugspew_indent_depth);
2045 if( res != 0) 2043 if( res != 0)
2046 { 2044 {
@@ -2067,7 +2065,7 @@ LUAG_FUNC( thread_new)
2067 int res; 2065 int res;
2068 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "thread_new: transfer lane arguments\n" INDENT_END)); 2066 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "thread_new: transfer lane arguments\n" INDENT_END));
2069 DEBUGSPEW_CODE( ++ debugspew_indent_depth); 2067 DEBUGSPEW_CODE( ++ debugspew_indent_depth);
2070 res = luaG_inter_copy( L, L2, args); // L->L2 2068 res = luaG_inter_copy( L, L2, args, eLM_LaneBody); // L->L2
2071 DEBUGSPEW_CODE( -- debugspew_indent_depth); 2069 DEBUGSPEW_CODE( -- debugspew_indent_depth);
2072 if( res != 0) 2070 if( res != 0)
2073 return luaL_error( L, "tried to copy unsupported types"); 2071 return luaL_error( L, "tried to copy unsupported types");
@@ -2317,7 +2315,7 @@ LUAG_FUNC( thread_join)
2317 case DONE: 2315 case DONE:
2318 { 2316 {
2319 uint_t n = lua_gettop( L2); // whole L2 stack 2317 uint_t n = lua_gettop( L2); // whole L2 stack
2320 if( (n > 0) && (luaG_inter_move( L2, L, n) != 0)) 2318 if( (n > 0) && (luaG_inter_move( L2, L, n, eLM_LaneBody) != 0))
2321 { 2319 {
2322 return luaL_error( L, "tried to copy unsupported types"); 2320 return luaL_error( L, "tried to copy unsupported types");
2323 } 2321 }
@@ -2327,7 +2325,7 @@ LUAG_FUNC( thread_join)
2327 2325
2328 case ERROR_ST: 2326 case ERROR_ST:
2329 lua_pushnil( L); 2327 lua_pushnil( L);
2330 if( luaG_inter_move( L2, L, 2) != 0) // error message at [-2], stack trace at [-1] 2328 if( luaG_inter_move( L2, L, 2, eLM_LaneBody) != 0) // error message at [-2], stack trace at [-1]
2331 { 2329 {
2332 return luaL_error( L, "tried to copy unsupported types"); 2330 return luaL_error( L, "tried to copy unsupported types");
2333 } 2331 }
@@ -2620,25 +2618,6 @@ static const struct luaL_Reg lanes_functions [] = {
2620 2618
2621 2619
2622/* 2620/*
2623 * minimal function registration for keepers, just so that we can populate the transfer databases with them
2624 * without recursively deadlocking ourselves during one-time inits
2625 */
2626void register_core_libfuncs_for_keeper( lua_State* L)
2627{
2628 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.register_core_libfuncs_for_keeper()\n" INDENT_END));
2629 DEBUGSPEW_CODE( ++ debugspew_indent_depth);
2630 STACK_GROW( L, 1);
2631 STACK_CHECK( L);
2632 lua_newtable( L);
2633 luaG_registerlibfuncs( L, lanes_functions);
2634 STACK_MID( L, 1);
2635 populate_func_lookup_table( L, -1, "lanes.core");
2636 lua_pop( L, 1);
2637 STACK_END( L, 0);
2638 DEBUGSPEW_CODE( -- debugspew_indent_depth);
2639}
2640
2641/*
2642** One-time initializations 2621** One-time initializations
2643*/ 2622*/
2644static void init_once_LOCKED( lua_State* L, int const _on_state_create, int const nbKeepers, lua_Number _shutdown_timeout, bool_t _track_lanes, bool_t verbose_errors) 2623static void init_once_LOCKED( lua_State* L, int const _on_state_create, int const nbKeepers, lua_Number _shutdown_timeout, bool_t _track_lanes, bool_t verbose_errors)