aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lanes.c')
-rw-r--r--src/lanes.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/lanes.c b/src/lanes.c
index f702685..cd1d4f1 100644
--- a/src/lanes.c
+++ b/src/lanes.c
@@ -174,7 +174,7 @@ static bool_t push_registry_table( lua_State* L, UniqueKey key, bool_t create)
174 return TRUE; // table pushed 174 return TRUE; // table pushed
175} 175}
176 176
177#if HAVE_LANE_TRACKING 177#if HAVE_LANE_TRACKING()
178 178
179// The chain is ended by '(Lane*)(-1)', not NULL: 179// The chain is ended by '(Lane*)(-1)', not NULL:
180// 'tracking_first -> ... -> ... -> (-1)' 180// 'tracking_first -> ... -> ... -> (-1)'
@@ -231,7 +231,7 @@ static bool_t tracking_remove( Lane* s)
231 return found; 231 return found;
232} 232}
233 233
234#endif // HAVE_LANE_TRACKING 234#endif // HAVE_LANE_TRACKING()
235 235
236//--- 236//---
237// low-level cleanup 237// low-level cleanup
@@ -245,23 +245,23 @@ static void lane_cleanup( Lane* s)
245 MUTEX_FREE( &s->done_lock); 245 MUTEX_FREE( &s->done_lock);
246#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR 246#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR
247 247
248#if HAVE_LANE_TRACKING 248#if HAVE_LANE_TRACKING()
249 if( s->U->tracking_first != NULL) 249 if( s->U->tracking_first != NULL)
250 { 250 {
251 // Lane was cleaned up, no need to handle at process termination 251 // Lane was cleaned up, no need to handle at process termination
252 tracking_remove( s); 252 tracking_remove( s);
253 } 253 }
254#endif // HAVE_LANE_TRACKING 254#endif // HAVE_LANE_TRACKING()
255 255
256 // don't hijack the state allocator when running LuaJIT because it looks like LuaJIT does not expect it and might invalidate the memory unexpectedly 256 // don't hijack the state allocator when running LuaJIT because it looks like LuaJIT does not expect it and might invalidate the memory unexpectedly
257#if USE_LUA_STATE_ALLOCATOR 257#if USE_LUA_STATE_ALLOCATOR()
258 { 258 {
259 AllocatorDefinition* const allocD = &s->U->protected_allocator.definition; 259 AllocatorDefinition* const allocD = &s->U->protected_allocator.definition;
260 allocD->allocF(allocD->allocUD, s, sizeof(Lane), 0); 260 allocD->allocF(allocD->allocUD, s, sizeof(Lane), 0);
261 } 261 }
262#else // USE_LUA_STATE_ALLOCATOR 262#else // USE_LUA_STATE_ALLOCATOR()
263 free(s); 263 free(s);
264#endif // USE_LUA_STATE_ALLOCATOR 264#endif // USE_LUA_STATE_ALLOCATOR()
265} 265}
266 266
267/* 267/*
@@ -589,9 +589,9 @@ static int selfdestruct_gc( lua_State* L)
589 // remove the protected allocator, if any 589 // remove the protected allocator, if any
590 cleanup_allocator_function( U, L); 590 cleanup_allocator_function( U, L);
591 591
592#if HAVE_LANE_TRACKING 592#if HAVE_LANE_TRACKING()
593 MUTEX_FREE( &U->tracking_cs); 593 MUTEX_FREE( &U->tracking_cs);
594#endif // HAVE_LANE_TRACKING 594#endif // HAVE_LANE_TRACKING()
595 // Linked chains handling 595 // Linked chains handling
596 MUTEX_FREE( &U->selfdestruct_cs); 596 MUTEX_FREE( &U->selfdestruct_cs);
597 MUTEX_FREE( &U->require_cs); 597 MUTEX_FREE( &U->require_cs);
@@ -844,7 +844,7 @@ LUAG_FUNC( set_thread_affinity)
844 return 0; 844 return 0;
845} 845}
846 846
847#if USE_DEBUG_SPEW 847#if USE_DEBUG_SPEW()
848// can't use direct LUA_x errcode indexing because the sequence is not the same between Lua 5.1 and 5.2 :-( 848// can't use direct LUA_x errcode indexing because the sequence is not the same between Lua 5.1 and 5.2 :-(
849// LUA_ERRERR doesn't have the same value 849// LUA_ERRERR doesn't have the same value
850struct errcode_name 850struct errcode_name
@@ -875,7 +875,7 @@ static char const* get_errcode_name( int _code)
875 } 875 }
876 return "<NULL>"; 876 return "<NULL>";
877} 877}
878#endif // USE_DEBUG_SPEW 878#endif // USE_DEBUG_SPEW()
879 879
880#if THREADWAIT_METHOD == THREADWAIT_CONDVAR // implies THREADAPI == THREADAPI_PTHREAD 880#if THREADWAIT_METHOD == THREADWAIT_CONDVAR // implies THREADAPI == THREADAPI_PTHREAD
881static void thread_cleanup_handler( void* opaque) 881static void thread_cleanup_handler( void* opaque)
@@ -1231,14 +1231,14 @@ LUAG_FUNC( lane_new)
1231 // a Lane full userdata needs a single uservalue 1231 // a Lane full userdata needs a single uservalue
1232 ud = lua_newuserdatauv( L, sizeof( Lane*), 1); // func libs priority globals package required gc_cb lane 1232 ud = lua_newuserdatauv( L, sizeof( Lane*), 1); // func libs priority globals package required gc_cb lane
1233 // don't hijack the state allocator when running LuaJIT because it looks like LuaJIT does not expect it and might invalidate the memory unexpectedly 1233 // don't hijack the state allocator when running LuaJIT because it looks like LuaJIT does not expect it and might invalidate the memory unexpectedly
1234#if USE_LUA_STATE_ALLOCATOR 1234#if USE_LUA_STATE_ALLOCATOR()
1235 { 1235 {
1236 AllocatorDefinition* const allocD = &U->protected_allocator.definition; 1236 AllocatorDefinition* const allocD = &U->protected_allocator.definition;
1237 s = *ud = (Lane*)allocD->allocF(allocD->allocUD, NULL, 0, sizeof(Lane)); 1237 s = *ud = (Lane*)allocD->allocF(allocD->allocUD, NULL, 0, sizeof(Lane));
1238 } 1238 }
1239#else // USE_LUA_STATE_ALLOCATOR 1239#else // USE_LUA_STATE_ALLOCATOR()
1240 s = *ud = (Lane*) malloc(sizeof(Lane)); 1240 s = *ud = (Lane*) malloc(sizeof(Lane));
1241#endif // USE_LUA_STATE_ALLOCATOR 1241#endif // USE_LUA_STATE_ALLOCATOR()
1242 if( s == NULL) 1242 if( s == NULL)
1243 { 1243 {
1244 return luaL_error( L, "could not create lane: out of memory"); 1244 return luaL_error( L, "could not create lane: out of memory");
@@ -1257,13 +1257,13 @@ LUAG_FUNC( lane_new)
1257#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR 1257#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR
1258 s->mstatus = NORMAL; 1258 s->mstatus = NORMAL;
1259 s->selfdestruct_next = NULL; 1259 s->selfdestruct_next = NULL;
1260#if HAVE_LANE_TRACKING 1260#if HAVE_LANE_TRACKING()
1261 s->tracking_next = NULL; 1261 s->tracking_next = NULL;
1262 if( s->U->tracking_first) 1262 if( s->U->tracking_first)
1263 { 1263 {
1264 tracking_add( s); 1264 tracking_add( s);
1265 } 1265 }
1266#endif // HAVE_LANE_TRACKING 1266#endif // HAVE_LANE_TRACKING()
1267 1267
1268 // Set metatable for the userdata 1268 // Set metatable for the userdata
1269 // 1269 //
@@ -1662,7 +1662,7 @@ LUAG_FUNC( thread_index)
1662 return 0; 1662 return 0;
1663} 1663}
1664 1664
1665#if HAVE_LANE_TRACKING 1665#if HAVE_LANE_TRACKING()
1666//--- 1666//---
1667// threads() -> {}|nil 1667// threads() -> {}|nil
1668// 1668//
@@ -1695,7 +1695,7 @@ LUAG_FUNC( threads)
1695 MUTEX_UNLOCK( &U->tracking_cs); 1695 MUTEX_UNLOCK( &U->tracking_cs);
1696 return lua_gettop( L) - top; // 0 or 1 1696 return lua_gettop( L) - top; // 0 or 1
1697} 1697}
1698#endif // HAVE_LANE_TRACKING 1698#endif // HAVE_LANE_TRACKING()
1699 1699
1700/* 1700/*
1701 * ############################################################################################### 1701 * ###############################################################################################
@@ -1893,12 +1893,12 @@ LUAG_FUNC( configure)
1893 lua_getfield( L, 1, "demote_full_userdata"); // settings demote_full_userdata 1893 lua_getfield( L, 1, "demote_full_userdata"); // settings demote_full_userdata
1894 U->demoteFullUserdata = lua_toboolean( L, -1); 1894 U->demoteFullUserdata = lua_toboolean( L, -1);
1895 lua_pop( L, 1); // settings 1895 lua_pop( L, 1); // settings
1896#if HAVE_LANE_TRACKING 1896#if HAVE_LANE_TRACKING()
1897 MUTEX_INIT( &U->tracking_cs); 1897 MUTEX_INIT( &U->tracking_cs);
1898 lua_getfield( L, 1, "track_lanes"); // settings track_lanes 1898 lua_getfield( L, 1, "track_lanes"); // settings track_lanes
1899 U->tracking_first = lua_toboolean( L, -1) ? TRACKING_END : NULL; 1899 U->tracking_first = lua_toboolean( L, -1) ? TRACKING_END : NULL;
1900 lua_pop( L, 1); // settings 1900 lua_pop( L, 1); // settings
1901#endif // HAVE_LANE_TRACKING 1901#endif // HAVE_LANE_TRACKING()
1902 // Linked chains handling 1902 // Linked chains handling
1903 MUTEX_INIT( &U->selfdestruct_cs); 1903 MUTEX_INIT( &U->selfdestruct_cs);
1904 MUTEX_RECURSIVE_INIT( &U->require_cs); 1904 MUTEX_RECURSIVE_INIT( &U->require_cs);
@@ -1935,14 +1935,14 @@ LUAG_FUNC( configure)
1935 lua_setfield( L, -2, "configure"); // settings M 1935 lua_setfield( L, -2, "configure"); // settings M
1936 // add functions to the module's table 1936 // add functions to the module's table
1937 luaG_registerlibfuncs( L, lanes_functions); 1937 luaG_registerlibfuncs( L, lanes_functions);
1938#if HAVE_LANE_TRACKING 1938#if HAVE_LANE_TRACKING()
1939 // register core.threads() only if settings say it should be available 1939 // register core.threads() only if settings say it should be available
1940 if( U->tracking_first != NULL) 1940 if( U->tracking_first != NULL)
1941 { 1941 {
1942 lua_pushcfunction( L, LG_threads); // settings M LG_threads() 1942 lua_pushcfunction( L, LG_threads); // settings M LG_threads()
1943 lua_setfield( L, -2, "threads"); // settings M 1943 lua_setfield( L, -2, "threads"); // settings M
1944 } 1944 }
1945#endif // HAVE_LANE_TRACKING 1945#endif // HAVE_LANE_TRACKING()
1946 STACK_MID( L, 2); 1946 STACK_MID( L, 2);
1947 1947
1948 { 1948 {