diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lanes.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/lanes.c b/src/lanes.c index 2b90caf..f4bef7b 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
@@ -989,6 +989,11 @@ static void selfdestruct_remove( struct s_lane *s ) { | |||
989 | MUTEX_UNLOCK( &selfdestruct_cs ); | 989 | MUTEX_UNLOCK( &selfdestruct_cs ); |
990 | } | 990 | } |
991 | 991 | ||
992 | // Initialized by 'init_once_LOCKED()': the deep userdata Linda object | ||
993 | // used for timers (each lane will get a proxy to this) | ||
994 | // | ||
995 | volatile DEEP_PRELUDE *timer_deep; // = NULL | ||
996 | |||
992 | /* | 997 | /* |
993 | * Process end; cancel any still free-running threads | 998 | * Process end; cancel any still free-running threads |
994 | */ | 999 | */ |
@@ -1008,6 +1013,10 @@ static void selfdestruct_atexit( void ) { | |||
1008 | } | 1013 | } |
1009 | MUTEX_UNLOCK( &selfdestruct_cs ); | 1014 | MUTEX_UNLOCK( &selfdestruct_cs ); |
1010 | 1015 | ||
1016 | // Tell the timer thread to check it's cancel request | ||
1017 | struct s_Linda *td = timer_deep->deep; | ||
1018 | SIGNAL_ALL( &td->write_happened); | ||
1019 | |||
1011 | // When noticing their cancel, the lanes will remove themselves from | 1020 | // When noticing their cancel, the lanes will remove themselves from |
1012 | // the selfdestruct chain. | 1021 | // the selfdestruct chain. |
1013 | 1022 | ||
@@ -1934,7 +1943,12 @@ static void init_once_LOCKED( lua_State *L, volatile DEEP_PRELUDE ** timer_deep_ | |||
1934 | *timer_deep_ref= * (DEEP_PRELUDE**) lua_touserdata( L, -1 ); | 1943 | *timer_deep_ref= * (DEEP_PRELUDE**) lua_touserdata( L, -1 ); |
1935 | ASSERT_L( (*timer_deep_ref) && (*timer_deep_ref)->refcount==1 && (*timer_deep_ref)->deep ); | 1944 | ASSERT_L( (*timer_deep_ref) && (*timer_deep_ref)->refcount==1 && (*timer_deep_ref)->deep ); |
1936 | 1945 | ||
1937 | lua_pop(L,1); // we don't need the proxy | 1946 | // The host Lua state must always have a reference to this Linda object in order for our 'timer_deep_ref' to be valid. |
1947 | // So store a reference that we will never actually use. | ||
1948 | lua_pushlightuserdata(L, (void *)init_once_LOCKED); | ||
1949 | lua_insert(L, -2); // Swap key with the Linda object | ||
1950 | lua_rawset(L, LUA_REGISTRYINDEX); | ||
1951 | |||
1938 | } | 1952 | } |
1939 | STACK_END(L,0) | 1953 | STACK_END(L,0) |
1940 | } | 1954 | } |
@@ -1945,11 +1959,6 @@ __declspec(dllexport) | |||
1945 | #endif | 1959 | #endif |
1946 | luaopen_lanes( lua_State *L ) { | 1960 | luaopen_lanes( lua_State *L ) { |
1947 | 1961 | ||
1948 | // Initialized by 'init_once_LOCKED()': the deep userdata Linda object | ||
1949 | // used for timers (each lane will get a proxy to this) | ||
1950 | // | ||
1951 | static volatile DEEP_PRELUDE *timer_deep; // = NULL | ||
1952 | |||
1953 | /* | 1962 | /* |
1954 | * Making one-time initializations. | 1963 | * Making one-time initializations. |
1955 | * | 1964 | * |