aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.c
diff options
context:
space:
mode:
authorBenoit Germain <bnt period germain arrobase gmail period com>2017-06-05 11:25:31 +0200
committerBenoit Germain <bnt period germain arrobase gmail period com>2017-06-05 11:25:31 +0200
commitc2ca1fce531e29f8209660b18ef0a493722813f1 (patch)
tree3afa59fb910b2aaee79cbccc9a58fc961b3b8868 /src/lanes.c
parent0ede50e2da00f2915ceb50184425c42bda83adfd (diff)
downloadlanes-c2ca1fce531e29f8209660b18ef0a493722813f1.tar.gz
lanes-c2ca1fce531e29f8209660b18ef0a493722813f1.tar.bz2
lanes-c2ca1fce531e29f8209660b18ef0a493722813f1.zip
Table transfer improvements
* new API function lanes.register( "name", module) to manually register a module table after it was required * Transfering registered module tables will link the equivalent in the destination state instead of cloning it * bumped version to 3.11
Diffstat (limited to 'src/lanes.c')
-rw-r--r--src/lanes.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/lanes.c b/src/lanes.c
index d0ffee1..8410ca2 100644
--- a/src/lanes.c
+++ b/src/lanes.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * LANES.C Copyright (c) 2007-08, Asko Kauppi 2 * LANES.C Copyright (c) 2007-08, Asko Kauppi
3 * Copyright (C) 2009-14, Benoit Germain 3 * Copyright (C) 2009-17, Benoit Germain
4 * 4 *
5 * Multithreading in Lua. 5 * Multithreading in Lua.
6 * 6 *
@@ -52,13 +52,13 @@
52 * ... 52 * ...
53 */ 53 */
54 54
55char const* VERSION = "3.10.1"; 55char const* VERSION = "3.11";
56 56
57/* 57/*
58=============================================================================== 58===============================================================================
59 59
60Copyright (C) 2007-10 Asko Kauppi <akauppi@gmail.com> 60Copyright (C) 2007-10 Asko Kauppi <akauppi@gmail.com>
61 2011-14 Benoit Germain <bnt.germain@gmail.com> 61 2011-17 Benoit Germain <bnt.germain@gmail.com>
62 62
63Permission is hereby granted, free of charge, to any person obtaining a copy 63Permission is hereby granted, free of charge, to any person obtaining a copy
64of this software and associated documentation files (the "Software"), to deal 64of this software and associated documentation files (the "Software"), to deal
@@ -162,7 +162,8 @@ struct s_lane
162 // lane status changes to DONE/ERROR_ST/CANCELLED. 162 // lane status changes to DONE/ERROR_ST/CANCELLED.
163#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR 163#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR
164 164
165 volatile enum { 165 volatile enum
166 {
166 NORMAL, // normal master side state 167 NORMAL, // normal master side state
167 KILLED // issued an OS kill 168 KILLED // issued an OS kill
168 } mstatus; 169 } mstatus;
@@ -307,7 +308,7 @@ static bool_t push_registry_table( lua_State* L, void* key, bool_t create)
307 return FALSE; 308 return FALSE;
308 } 309 }
309 310
310 lua_newtable(L); // t 311 lua_newtable( L); // t
311 lua_pushlightuserdata( L, key); // t key 312 lua_pushlightuserdata( L, key); // t key
312 lua_pushvalue( L, -2); // t key t 313 lua_pushvalue( L, -2); // t key t
313 lua_rawset( L, LUA_REGISTRYINDEX); // t 314 lua_rawset( L, LUA_REGISTRYINDEX); // t
@@ -351,7 +352,7 @@ static bool_t tracking_remove( struct s_lane* s)
351 // still (at process exit they will remove us from chain and then 352 // still (at process exit they will remove us from chain and then
352 // cancel/kill). 353 // cancel/kill).
353 // 354 //
354 if (s->tracking_next != NULL) 355 if( s->tracking_next != NULL)
355 { 356 {
356 struct s_lane** ref = (struct s_lane**) &s->U->tracking_first; 357 struct s_lane** ref = (struct s_lane**) &s->U->tracking_first;
357 358
@@ -539,7 +540,7 @@ LUAG_FUNC( linda_send)
539 break; 540 break;
540 } 541 }
541 542
542 // instant timout to bypass the 543 // instant timout to bypass the wait syscall
543 if( timeout == 0.0) 544 if( timeout == 0.0)
544 { 545 {
545 break; /* no wait; instant timeout */ 546 break; /* no wait; instant timeout */
@@ -2157,6 +2158,30 @@ LUAG_FUNC( require)
2157 return 1; 2158 return 1;
2158} 2159}
2159 2160
2161
2162// --- If a client wants to transfer stuff of a previously required module from the current state to another Lane, the module must be registered
2163// to populate the lookup database in the source lane (and in the destination too, of course)
2164// lanes.register( "modname", module)
2165LUAG_FUNC( register)
2166{
2167 char const* name = luaL_checkstring( L, 1);
2168 int const nargs = lua_gettop( L);
2169 int const mod_type = lua_type( L, 2);
2170 // ignore extra parameters, just in case
2171 lua_settop( L, 2);
2172 luaL_argcheck( L, (mod_type == LUA_TTABLE) || (mod_type == LUA_TFUNCTION), 2, "unexpected module type");
2173 DEBUGSPEW_CODE( struct s_Universe* U = get_universe( L));
2174 STACK_CHECK( L); // "name" mod_table
2175 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.register %s BEGIN\n" INDENT_END, name));
2176 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
2177 populate_func_lookup_table( L, -1, name);
2178 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.register %s END\n" INDENT_END, name));
2179 DEBUGSPEW_CODE( -- U->debugspew_indent_depth);
2180 STACK_END( L, 0);
2181 return 0;
2182}
2183
2184
2160LUAG_FUNC( thread_gc); 2185LUAG_FUNC( thread_gc);
2161#define GCCB_KEY (void*)LG_thread_gc 2186#define GCCB_KEY (void*)LG_thread_gc
2162//--- 2187//---
@@ -2945,6 +2970,7 @@ static const struct luaL_Reg lanes_functions [] = {
2945 {"wakeup_conv", LG_wakeup_conv}, 2970 {"wakeup_conv", LG_wakeup_conv},
2946 {"set_thread_priority", LG_set_thread_priority}, 2971 {"set_thread_priority", LG_set_thread_priority},
2947 {"nameof", luaG_nameof}, 2972 {"nameof", luaG_nameof},
2973 {"register", LG_register},
2948 {"set_singlethreaded", LG_set_singlethreaded}, 2974 {"set_singlethreaded", LG_set_singlethreaded},
2949 {NULL, NULL} 2975 {NULL, NULL}
2950}; 2976};
@@ -3201,7 +3227,7 @@ LUAG_FUNC( configure)
3201 { 3227 {
3202 // don't do this when called during the initialization of a new lane, 3228 // don't do this when called during the initialization of a new lane,
3203 // because we will do it after on_state_create() is called, 3229 // because we will do it after on_state_create() is called,
3204 // and we don't want skip _G because of caching in case globals are created then 3230 // and we don't want to skip _G because of caching in case globals are created then
3205 lua_pushglobaltable( L); // settings M _G 3231 lua_pushglobaltable( L); // settings M _G
3206 populate_func_lookup_table( L, -1, NULL); 3232 populate_func_lookup_table( L, -1, NULL);
3207 lua_pop( L, 1); // settings M 3233 lua_pop( L, 1); // settings M