aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lanes.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/src/lanes.c b/src/lanes.c
index 78fece8..3268c8b 100644
--- a/src/lanes.c
+++ b/src/lanes.c
@@ -52,7 +52,7 @@
52 * ... 52 * ...
53 */ 53 */
54 54
55char const* VERSION = "3.11"; 55char const* VERSION = "3.12";
56 56
57/* 57/*
58=============================================================================== 58===============================================================================
@@ -89,6 +89,7 @@ THE SOFTWARE.
89#include "threading.h" 89#include "threading.h"
90#include "compat.h" 90#include "compat.h"
91#include "tools.h" 91#include "tools.h"
92#include "universe.h"
92#include "keeper.h" 93#include "keeper.h"
93#include "lanes.h" 94#include "lanes.h"
94 95
@@ -1070,7 +1071,7 @@ LUAG_FUNC( linda_concat)
1070LUAG_FUNC( linda_dump) 1071LUAG_FUNC( linda_dump)
1071{ 1072{
1072 struct s_Linda* linda = lua_toLinda( L, 1); 1073 struct s_Linda* linda = lua_toLinda( L, 1);
1073 ASSERT_L( linda->U == get_universe( L)); 1074 ASSERT_L( linda->U == universe_get( L));
1074 return keeper_push_linda_storage( linda->U, L, linda, LINDA_KEEPER_HASHSEED( linda)); 1075 return keeper_push_linda_storage( linda->U, L, linda, LINDA_KEEPER_HASHSEED( linda));
1075} 1076}
1076 1077
@@ -1082,7 +1083,7 @@ LUAG_FUNC( linda_towatch)
1082{ 1083{
1083 struct s_Linda* linda = lua_toLinda( L, 1); 1084 struct s_Linda* linda = lua_toLinda( L, 1);
1084 int pushed; 1085 int pushed;
1085 ASSERT_L( linda->U == get_universe( L)); 1086 ASSERT_L( linda->U == universe_get( L));
1086 pushed = keeper_push_linda_storage( linda->U, L, linda, LINDA_KEEPER_HASHSEED( linda)); 1087 pushed = keeper_push_linda_storage( linda->U, L, linda, LINDA_KEEPER_HASHSEED( linda));
1087 if( pushed == 0) 1088 if( pushed == 0)
1088 { 1089 {
@@ -1159,7 +1160,7 @@ static void* linda_id( lua_State* L, enum eDeepOp op_)
1159 { 1160 {
1160 SIGNAL_INIT( &s->read_happened); 1161 SIGNAL_INIT( &s->read_happened);
1161 SIGNAL_INIT( &s->write_happened); 1162 SIGNAL_INIT( &s->write_happened);
1162 s->U = get_universe( L); 1163 s->U = universe_get( L);
1163 s->simulate_cancel = CANCEL_NONE; 1164 s->simulate_cancel = CANCEL_NONE;
1164 s->group = linda_group << KEEPER_MAGIC_SHIFT; 1165 s->group = linda_group << KEEPER_MAGIC_SHIFT;
1165 s->name[0] = 0; 1166 s->name[0] = 0;
@@ -1718,7 +1719,7 @@ static int selfdestruct_gc( lua_State* L)
1718 lua_settop( L, 0); 1719 lua_settop( L, 0);
1719 // no need to mutex-protect this as all threads in the universe are gone at that point 1720 // no need to mutex-protect this as all threads in the universe are gone at that point
1720 -- U->timer_deep->refcount; // should be 0 now 1721 -- U->timer_deep->refcount; // should be 0 now
1721 free_deep_prelude( L, (DEEP_PRELUDE*) U->timer_deep); 1722 free_deep_prelude( L, (struct DEEP_PRELUDE*) U->timer_deep);
1722 U->timer_deep = NULL; 1723 U->timer_deep = NULL;
1723 1724
1724 close_keepers( U, L); 1725 close_keepers( U, L);
@@ -2045,7 +2046,7 @@ static THREAD_RETURN_T THREAD_CALLCONV lane_main( void* vs)
2045 lua_State* L = s->L; 2046 lua_State* L = s->L;
2046 // Called with the lane function and arguments on the stack 2047 // Called with the lane function and arguments on the stack
2047 int const nargs = lua_gettop( L) - 1; 2048 int const nargs = lua_gettop( L) - 1;
2048 DEBUGSPEW_CODE( struct s_Universe* U = get_universe( L)); 2049 DEBUGSPEW_CODE( struct s_Universe* U = universe_get( L));
2049 THREAD_MAKE_ASYNCH_CANCELLABLE(); 2050 THREAD_MAKE_ASYNCH_CANCELLABLE();
2050 THREAD_CLEANUP_PUSH( thread_cleanup_handler, s); 2051 THREAD_CLEANUP_PUSH( thread_cleanup_handler, s);
2051 s->status = RUNNING; // PENDING -> RUNNING 2052 s->status = RUNNING; // PENDING -> RUNNING
@@ -2143,7 +2144,7 @@ LUAG_FUNC( require)
2143{ 2144{
2144 char const* name = lua_tostring( L, 1); 2145 char const* name = lua_tostring( L, 1);
2145 int const nargs = lua_gettop( L); 2146 int const nargs = lua_gettop( L);
2146 DEBUGSPEW_CODE( struct s_Universe* U = get_universe( L)); 2147 DEBUGSPEW_CODE( struct s_Universe* U = universe_get( L));
2147 STACK_CHECK( L); 2148 STACK_CHECK( L);
2148 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.require %s BEGIN\n" INDENT_END, name)); 2149 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.require %s BEGIN\n" INDENT_END, name));
2149 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 2150 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
@@ -2169,7 +2170,7 @@ LUAG_FUNC( register)
2169 // ignore extra parameters, just in case 2170 // ignore extra parameters, just in case
2170 lua_settop( L, 2); 2171 lua_settop( L, 2);
2171 luaL_argcheck( L, (mod_type == LUA_TTABLE) || (mod_type == LUA_TFUNCTION), 2, "unexpected module type"); 2172 luaL_argcheck( L, (mod_type == LUA_TTABLE) || (mod_type == LUA_TFUNCTION), 2, "unexpected module type");
2172 DEBUGSPEW_CODE( struct s_Universe* U = get_universe( L)); 2173 DEBUGSPEW_CODE( struct s_Universe* U = universe_get( L));
2173 STACK_CHECK( L); // "name" mod_table 2174 STACK_CHECK( L); // "name" mod_table
2174 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.register %s BEGIN\n" INDENT_END, name)); 2175 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.register %s BEGIN\n" INDENT_END, name));
2175 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 2176 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
@@ -2212,7 +2213,7 @@ LUAG_FUNC( lane_new)
2212 2213
2213#define FIXED_ARGS 8 2214#define FIXED_ARGS 8
2214 int const nargs = lua_gettop(L) - FIXED_ARGS; 2215 int const nargs = lua_gettop(L) - FIXED_ARGS;
2215 struct s_Universe* U = get_universe( L); 2216 struct s_Universe* U = universe_get( L);
2216 ASSERT_L( nargs >= 0); 2217 ASSERT_L( nargs >= 0);
2217 2218
2218 // public Lanes API accepts a generic range -3/+3 2219 // public Lanes API accepts a generic range -3/+3
@@ -2660,7 +2661,7 @@ LUAG_FUNC( thread_join)
2660 } 2661 }
2661 else 2662 else
2662 { 2663 {
2663 struct s_Universe* U = get_universe( L); 2664 struct s_Universe* U = universe_get( L);
2664 // debug_name is a pointer to string possibly interned in the lane's state, that no longer exists when the state is closed 2665 // debug_name is a pointer to string possibly interned in the lane's state, that no longer exists when the state is closed
2665 // so store it in the userdata uservalue at a key that can't possibly collide 2666 // so store it in the userdata uservalue at a key that can't possibly collide
2666 securize_debug_threadname( L, s); 2667 securize_debug_threadname( L, s);
@@ -2872,7 +2873,7 @@ LUAG_FUNC( thread_index)
2872LUAG_FUNC( threads) 2873LUAG_FUNC( threads)
2873{ 2874{
2874 int const top = lua_gettop( L); 2875 int const top = lua_gettop( L);
2875 struct s_Universe* U = get_universe( L); 2876 struct s_Universe* U = universe_get( L);
2876 2877
2877 // List _all_ still running threads 2878 // List _all_ still running threads
2878 // 2879 //
@@ -3024,7 +3025,7 @@ static volatile long s_initCount = 0;
3024// param 1: settings table 3025// param 1: settings table
3025LUAG_FUNC( configure) 3026LUAG_FUNC( configure)
3026{ 3027{
3027 struct s_Universe* U = get_universe( L); 3028 struct s_Universe* U = universe_get( L);
3028 bool_t const from_master_state = (U == NULL); 3029 bool_t const from_master_state = (U == NULL);
3029 char const* name = luaL_checkstring( L, lua_upvalueindex( 1)); 3030 char const* name = luaL_checkstring( L, lua_upvalueindex( 1));
3030 _ASSERT_L( L, lua_type( L, 1) == LUA_TTABLE); 3031 _ASSERT_L( L, lua_type( L, 1) == LUA_TTABLE);
@@ -3093,16 +3094,14 @@ LUAG_FUNC( configure)
3093 // grab or create the universe 3094 // grab or create the universe
3094 if( U == NULL) 3095 if( U == NULL)
3095 { 3096 {
3096 lua_pushlightuserdata( L, UNIVERSE_REGKEY); // settings UNIVERSE_REGKEY 3097 U = universe_create( L); // settings universe
3097 U = (struct s_Universe*) lua_newuserdata( L, sizeof( struct s_Universe)); // settings UNIVERSE_REGKEY universe
3098 memset( U, 0, sizeof( struct s_Universe));
3099 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 3098 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
3100 lua_newtable( L); // settings UNIVERSE_REGKEY universe mt 3099 lua_newtable( L); // settings universe mt
3101 lua_getfield( L, 1, "shutdown_timeout"); // settings UNIVERSE_REGKEY universe mt shutdown_timeout 3100 lua_getfield( L, 1, "shutdown_timeout"); // settings universe mt shutdown_timeout
3102 lua_pushcclosure( L, selfdestruct_gc, 1); // settings UNIVERSE_REGKEY universe mt selfdestruct_gc 3101 lua_pushcclosure( L, selfdestruct_gc, 1); // settings universe mt selfdestruct_gc
3103 lua_setfield( L, -2, "__gc"); // settings UNIVERSE_REGKEY universe mt 3102 lua_setfield( L, -2, "__gc"); // settings universe mt
3104 lua_setmetatable( L, -2); // settings UNIVERSE_REGKEY universe 3103 lua_setmetatable( L, -2); // settings universe
3105 lua_rawset( L, LUA_REGISTRYINDEX); // settings 3104 lua_pop( L, 1); // settings
3106 lua_getfield( L, 1, "verbose_errors"); // settings verbose_errors 3105 lua_getfield( L, 1, "verbose_errors"); // settings verbose_errors
3107 U->verboseErrors = lua_toboolean( L, -1); 3106 U->verboseErrors = lua_toboolean( L, -1);
3108 lua_pop( L, 1); // settings 3107 lua_pop( L, 1); // settings
@@ -3130,7 +3129,7 @@ LUAG_FUNC( configure)
3130 STACK_MID( L, 1); 3129 STACK_MID( L, 1);
3131 3130
3132 // Proxy userdata contents is only a 'DEEP_PRELUDE*' pointer 3131 // Proxy userdata contents is only a 'DEEP_PRELUDE*' pointer
3133 U->timer_deep = * (DEEP_PRELUDE**) lua_touserdata( L, -1); 3132 U->timer_deep = *(struct DEEP_PRELUDE**) lua_touserdata( L, -1);
3134 ASSERT_L( U->timer_deep && (U->timer_deep->refcount == 1) && U->timer_deep->deep && U->timer_deep->idfunc == linda_id); 3133 ASSERT_L( U->timer_deep && (U->timer_deep->refcount == 1) && U->timer_deep->deep && U->timer_deep->idfunc == linda_id);
3135 // increment refcount that this linda remains alive as long as the universe is. 3134 // increment refcount that this linda remains alive as long as the universe is.
3136 ++ U->timer_deep->refcount; 3135 ++ U->timer_deep->refcount;
@@ -3160,7 +3159,7 @@ LUAG_FUNC( configure)
3160 3159
3161 { 3160 {
3162 char const* errmsg; 3161 char const* errmsg;
3163 errmsg = push_deep_proxy( U, L, (DEEP_PRELUDE*) U->timer_deep, eLM_LaneBody); // settings M timer_deep 3162 errmsg = push_deep_proxy( U, L, (struct DEEP_PRELUDE*) U->timer_deep, eLM_LaneBody);// settings M timer_deep
3164 if( errmsg != NULL) 3163 if( errmsg != NULL)
3165 { 3164 {
3166 return luaL_error( L, errmsg); 3165 return luaL_error( L, errmsg);