aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lanes.cpp')
-rw-r--r--src/lanes.cpp62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp
index deee90c..d97a539 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -176,7 +176,7 @@ static bool_t push_registry_table( lua_State* L, UniqueKey key, bool_t create)
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 nullptr:
180// 'tracking_first -> ... -> ... -> (-1)' 180// 'tracking_first -> ... -> ... -> (-1)'
181#define TRACKING_END ((Lane *)(-1)) 181#define TRACKING_END ((Lane *)(-1))
182 182
@@ -189,7 +189,7 @@ static void tracking_add( Lane* s)
189 189
190 MUTEX_LOCK( &s->U->tracking_cs); 190 MUTEX_LOCK( &s->U->tracking_cs);
191 { 191 {
192 assert( s->tracking_next == NULL); 192 assert( s->tracking_next == nullptr);
193 193
194 s->tracking_next = s->U->tracking_first; 194 s->tracking_next = s->U->tracking_first;
195 s->U->tracking_first = s; 195 s->U->tracking_first = s;
@@ -209,7 +209,7 @@ static bool_t tracking_remove( Lane* s)
209 // still (at process exit they will remove us from chain and then 209 // still (at process exit they will remove us from chain and then
210 // cancel/kill). 210 // cancel/kill).
211 // 211 //
212 if( s->tracking_next != NULL) 212 if( s->tracking_next != nullptr)
213 { 213 {
214 Lane** ref = (Lane**) &s->U->tracking_first; 214 Lane** ref = (Lane**) &s->U->tracking_first;
215 215
@@ -218,7 +218,7 @@ static bool_t tracking_remove( Lane* s)
218 if( *ref == s) 218 if( *ref == s)
219 { 219 {
220 *ref = s->tracking_next; 220 *ref = s->tracking_next;
221 s->tracking_next = NULL; 221 s->tracking_next = nullptr;
222 found = TRUE; 222 found = TRUE;
223 break; 223 break;
224 } 224 }
@@ -246,7 +246,7 @@ static void lane_cleanup( Lane* s)
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 != nullptr)
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);
@@ -386,7 +386,7 @@ static int run_finalizers( lua_State* L, int lua_rc)
386 386
387#define SELFDESTRUCT_END ((Lane*)(-1)) 387#define SELFDESTRUCT_END ((Lane*)(-1))
388// 388//
389// The chain is ended by '(Lane*)(-1)', not NULL: 389// The chain is ended by '(Lane*)(-1)', not nullptr:
390// 'selfdestruct_first -> ... -> ... -> (-1)' 390// 'selfdestruct_first -> ... -> ... -> (-1)'
391 391
392/* 392/*
@@ -396,7 +396,7 @@ static int run_finalizers( lua_State* L, int lua_rc)
396static void selfdestruct_add( Lane* s) 396static void selfdestruct_add( Lane* s)
397{ 397{
398 MUTEX_LOCK( &s->U->selfdestruct_cs); 398 MUTEX_LOCK( &s->U->selfdestruct_cs);
399 assert( s->selfdestruct_next == NULL); 399 assert( s->selfdestruct_next == nullptr);
400 400
401 s->selfdestruct_next = s->U->selfdestruct_first; 401 s->selfdestruct_next = s->U->selfdestruct_first;
402 s->U->selfdestruct_first= s; 402 s->U->selfdestruct_first= s;
@@ -415,7 +415,7 @@ static bool_t selfdestruct_remove( Lane* s)
415 // still (at process exit they will remove us from chain and then 415 // still (at process exit they will remove us from chain and then
416 // cancel/kill). 416 // cancel/kill).
417 // 417 //
418 if( s->selfdestruct_next != NULL) 418 if( s->selfdestruct_next != nullptr)
419 { 419 {
420 Lane** ref = (Lane**) &s->U->selfdestruct_first; 420 Lane** ref = (Lane**) &s->U->selfdestruct_first;
421 421
@@ -424,7 +424,7 @@ static bool_t selfdestruct_remove( Lane* s)
424 if( *ref == s) 424 if( *ref == s)
425 { 425 {
426 *ref = s->selfdestruct_next; 426 *ref = s->selfdestruct_next;
427 s->selfdestruct_next = NULL; 427 s->selfdestruct_next = nullptr;
428 // the terminal shutdown should wait until the lane is done with its lua_close() 428 // the terminal shutdown should wait until the lane is done with its lua_close()
429 ++ s->U->selfdestructing_count; 429 ++ s->U->selfdestructing_count;
430 found = TRUE; 430 found = TRUE;
@@ -458,12 +458,12 @@ static int selfdestruct_gc( lua_State* L)
458 // attempt a regular unforced hard cancel with a small timeout 458 // attempt a regular unforced hard cancel with a small timeout
459 bool_t cancelled = THREAD_ISNULL( s->thread) || thread_cancel( L, s, CO_Hard, 0.0001, FALSE, 0.0); 459 bool_t cancelled = THREAD_ISNULL( s->thread) || thread_cancel( L, s, CO_Hard, 0.0001, FALSE, 0.0);
460 // if we failed, and we know the thread is waiting on a linda 460 // if we failed, and we know the thread is waiting on a linda
461 if( cancelled == FALSE && s->status == WAITING && s->waiting_on != NULL) 461 if( cancelled == FALSE && s->status == WAITING && s->waiting_on != nullptr)
462 { 462 {
463 // signal the linda to wake up the thread so that it can react to the cancel query 463 // signal the linda to wake up the thread so that it can react to the cancel query
464 // let us hope we never land here with a pointer on a linda that has been destroyed... 464 // let us hope we never land here with a pointer on a linda that has been destroyed...
465 SIGNAL_T* waiting_on = s->waiting_on; 465 SIGNAL_T* waiting_on = s->waiting_on;
466 //s->waiting_on = NULL; // useful, or not? 466 //s->waiting_on = nullptr; // useful, or not?
467 SIGNAL_ALL( waiting_on); 467 SIGNAL_ALL( waiting_on);
468 } 468 }
469 s = s->selfdestruct_next; 469 s = s->selfdestruct_next;
@@ -540,8 +540,8 @@ static int selfdestruct_gc( lua_State* L)
540 while( s != SELFDESTRUCT_END) 540 while( s != SELFDESTRUCT_END)
541 { 541 {
542 Lane* next_s = s->selfdestruct_next; 542 Lane* next_s = s->selfdestruct_next;
543 s->selfdestruct_next = NULL; // detach from selfdestruct chain 543 s->selfdestruct_next = nullptr; // detach from selfdestruct chain
544 if( !THREAD_ISNULL( s->thread)) // can be NULL if previous 'soft' termination succeeded 544 if( !THREAD_ISNULL( s->thread)) // can be nullptr if previous 'soft' termination succeeded
545 { 545 {
546 THREAD_KILL( &s->thread); 546 THREAD_KILL( &s->thread);
547#if THREADAPI == THREADAPI_PTHREAD 547#if THREADAPI == THREADAPI_PTHREAD
@@ -572,11 +572,11 @@ static int selfdestruct_gc( lua_State* L)
572 // necessary so that calling free_deep_prelude doesn't crash because linda_id expects a linda lightuserdata at absolute slot 1 572 // necessary so that calling free_deep_prelude doesn't crash because linda_id expects a linda lightuserdata at absolute slot 1
573 lua_settop( L, 0); 573 lua_settop( L, 0);
574 // no need to mutex-protect this as all threads in the universe are gone at that point 574 // no need to mutex-protect this as all threads in the universe are gone at that point
575 if( U->timer_deep != NULL) // test ins case some early internal error prevented Lanes from creating the deep timer 575 if( U->timer_deep != nullptr) // test ins case some early internal error prevented Lanes from creating the deep timer
576 { 576 {
577 -- U->timer_deep->refcount; // should be 0 now 577 -- U->timer_deep->refcount; // should be 0 now
578 free_deep_prelude( L, (DeepPrelude*) U->timer_deep); 578 free_deep_prelude( L, (DeepPrelude*) U->timer_deep);
579 U->timer_deep = NULL; 579 U->timer_deep = nullptr;
580 } 580 }
581 581
582 close_keepers( U); 582 close_keepers( U);
@@ -596,7 +596,7 @@ static int selfdestruct_gc( lua_State* L)
596 // universe is no longer available (nor necessary) 596 // universe is no longer available (nor necessary)
597 // we need to do this in case some deep userdata objects were created before Lanes was initialized, 597 // we need to do this in case some deep userdata objects were created before Lanes was initialized,
598 // as potentially they will be garbage collected after Lanes at application shutdown 598 // as potentially they will be garbage collected after Lanes at application shutdown
599 universe_store( L, NULL); 599 universe_store( L, nullptr);
600 return 0; 600 return 0;
601} 601}
602 602
@@ -868,7 +868,7 @@ static char const* get_errcode_name( int _code)
868 return s_errcodes[i].name; 868 return s_errcodes[i].name;
869 } 869 }
870 } 870 }
871 return "<NULL>"; 871 return "<nullptr>";
872} 872}
873#endif // USE_DEBUG_SPEW() 873#endif // USE_DEBUG_SPEW()
874 874
@@ -943,7 +943,7 @@ static THREAD_RETURN_T THREAD_CALLCONV lane_main( void* vs)
943 // the finalizer generated an error, and left its own error message [and stack trace] on the stack 943 // the finalizer generated an error, and left its own error message [and stack trace] on the stack
944 rc = rc2; // we're overruling the earlier script error or normal return 944 rc = rc2; // we're overruling the earlier script error or normal return
945 } 945 }
946 s->waiting_on = NULL; // just in case 946 s->waiting_on = nullptr; // just in case
947 if( selfdestruct_remove( s)) // check and remove (under lock!) 947 if( selfdestruct_remove( s)) // check and remove (under lock!)
948 { 948 {
949 // We're a free-running thread and no-one's there to clean us up. 949 // We're a free-running thread and no-one's there to clean us up.
@@ -1228,9 +1228,9 @@ LUAG_FUNC( lane_new)
1228 ud = (Lane**) lua_newuserdatauv( L, sizeof( Lane*), 1); // func libs priority globals package required gc_cb lane 1228 ud = (Lane**) lua_newuserdatauv( L, sizeof( Lane*), 1); // func libs priority globals package required gc_cb lane
1229 { 1229 {
1230 AllocatorDefinition* const allocD = &U->internal_allocator; 1230 AllocatorDefinition* const allocD = &U->internal_allocator;
1231 s = *ud = (Lane*) allocD->allocF(allocD->allocUD, NULL, 0, sizeof(Lane)); 1231 s = *ud = (Lane*) allocD->allocF(allocD->allocUD, nullptr, 0, sizeof(Lane));
1232 } 1232 }
1233 if( s == NULL) 1233 if( s == nullptr)
1234 { 1234 {
1235 return luaL_error( L, "could not create lane: out of memory"); 1235 return luaL_error( L, "could not create lane: out of memory");
1236 } 1236 }
@@ -1238,7 +1238,7 @@ LUAG_FUNC( lane_new)
1238 s->L = L2; 1238 s->L = L2;
1239 s->U = U; 1239 s->U = U;
1240 s->status = PENDING; 1240 s->status = PENDING;
1241 s->waiting_on = NULL; 1241 s->waiting_on = nullptr;
1242 s->debug_name = "<unnamed>"; 1242 s->debug_name = "<unnamed>";
1243 s->cancel_request = CANCEL_NONE; 1243 s->cancel_request = CANCEL_NONE;
1244 1244
@@ -1247,9 +1247,9 @@ LUAG_FUNC( lane_new)
1247 SIGNAL_INIT( &s->done_signal); 1247 SIGNAL_INIT( &s->done_signal);
1248#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR 1248#endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR
1249 s->mstatus = NORMAL; 1249 s->mstatus = NORMAL;
1250 s->selfdestruct_next = NULL; 1250 s->selfdestruct_next = nullptr;
1251#if HAVE_LANE_TRACKING() 1251#if HAVE_LANE_TRACKING()
1252 s->tracking_next = NULL; 1252 s->tracking_next = nullptr;
1253 if( s->U->tracking_first) 1253 if( s->U->tracking_first)
1254 { 1254 {
1255 tracking_add( s); 1255 tracking_add( s);
@@ -1399,7 +1399,7 @@ static char const * thread_status_string( Lane* s)
1399 (st == WAITING) ? "waiting" : 1399 (st == WAITING) ? "waiting" :
1400 (st == DONE) ? "done" : 1400 (st == DONE) ? "done" :
1401 (st == ERROR_ST) ? "error" : 1401 (st == ERROR_ST) ? "error" :
1402 (st == CANCELLED) ? "cancelled" : NULL; 1402 (st == CANCELLED) ? "cancelled" : nullptr;
1403 return str; 1403 return str;
1404} 1404}
1405 1405
@@ -1767,7 +1767,7 @@ static const struct luaL_Reg lanes_functions [] = {
1767 {"nameof", luaG_nameof}, 1767 {"nameof", luaG_nameof},
1768 {"register", LG_register}, 1768 {"register", LG_register},
1769 {"set_singlethreaded", LG_set_singlethreaded}, 1769 {"set_singlethreaded", LG_set_singlethreaded},
1770 {NULL, NULL} 1770 {nullptr, nullptr}
1771}; 1771};
1772 1772
1773/* 1773/*
@@ -1820,7 +1820,7 @@ static volatile long s_initCount = 0;
1820LUAG_FUNC( configure) 1820LUAG_FUNC( configure)
1821{ 1821{
1822 Universe* U = universe_get( L); 1822 Universe* U = universe_get( L);
1823 bool_t const from_master_state = (U == NULL); 1823 bool_t const from_master_state = (U == nullptr);
1824 char const* name = luaL_checkstring( L, lua_upvalueindex( 1)); 1824 char const* name = luaL_checkstring( L, lua_upvalueindex( 1));
1825 _ASSERT_L( L, lua_type( L, 1) == LUA_TTABLE); 1825 _ASSERT_L( L, lua_type( L, 1) == LUA_TTABLE);
1826 1826
@@ -1868,7 +1868,7 @@ LUAG_FUNC( configure)
1868 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() BEGIN\n" INDENT_END, L)); 1868 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() BEGIN\n" INDENT_END, L));
1869 DEBUGSPEW_CODE( if( U) ++ U->debugspew_indent_depth); 1869 DEBUGSPEW_CODE( if( U) ++ U->debugspew_indent_depth);
1870 1870
1871 if( U == NULL) 1871 if( U == nullptr)
1872 { 1872 {
1873 U = universe_create( L); // settings universe 1873 U = universe_create( L); // settings universe
1874 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 1874 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
@@ -1887,7 +1887,7 @@ LUAG_FUNC( configure)
1887#if HAVE_LANE_TRACKING() 1887#if HAVE_LANE_TRACKING()
1888 MUTEX_INIT( &U->tracking_cs); 1888 MUTEX_INIT( &U->tracking_cs);
1889 lua_getfield( L, 1, "track_lanes"); // settings track_lanes 1889 lua_getfield( L, 1, "track_lanes"); // settings track_lanes
1890 U->tracking_first = lua_toboolean( L, -1) ? TRACKING_END : NULL; 1890 U->tracking_first = lua_toboolean( L, -1) ? TRACKING_END : nullptr;
1891 lua_pop( L, 1); // settings 1891 lua_pop( L, 1); // settings
1892#endif // HAVE_LANE_TRACKING() 1892#endif // HAVE_LANE_TRACKING()
1893 // Linked chains handling 1893 // Linked chains handling
@@ -1928,7 +1928,7 @@ LUAG_FUNC( configure)
1928 luaG_registerlibfuncs( L, lanes_functions); 1928 luaG_registerlibfuncs( L, lanes_functions);
1929#if HAVE_LANE_TRACKING() 1929#if HAVE_LANE_TRACKING()
1930 // register core.threads() only if settings say it should be available 1930 // register core.threads() only if settings say it should be available
1931 if( U->tracking_first != NULL) 1931 if( U->tracking_first != nullptr)
1932 { 1932 {
1933 lua_pushcfunction( L, LG_threads); // settings M LG_threads() 1933 lua_pushcfunction( L, LG_threads); // settings M LG_threads()
1934 lua_setfield( L, -2, "threads"); // settings M 1934 lua_setfield( L, -2, "threads"); // settings M
@@ -1939,7 +1939,7 @@ LUAG_FUNC( configure)
1939 { 1939 {
1940 char const* errmsg; 1940 char const* errmsg;
1941 errmsg = push_deep_proxy( U, L, (DeepPrelude*) U->timer_deep, 0, eLM_LaneBody); // settings M timer_deep 1941 errmsg = push_deep_proxy( U, L, (DeepPrelude*) U->timer_deep, 0, eLM_LaneBody); // settings M timer_deep
1942 if( errmsg != NULL) 1942 if( errmsg != nullptr)
1943 { 1943 {
1944 return luaL_error( L, errmsg); 1944 return luaL_error( L, errmsg);
1945 } 1945 }
@@ -2011,7 +2011,7 @@ LUAG_FUNC( configure)
2011 // because we will do it after on_state_create() is called, 2011 // because we will do it after on_state_create() is called,
2012 // and we don't want to skip _G because of caching in case globals are created then 2012 // and we don't want to skip _G because of caching in case globals are created then
2013 lua_pushglobaltable( L); // settings M _G 2013 lua_pushglobaltable( L); // settings M _G
2014 populate_func_lookup_table( L, -1, NULL); 2014 populate_func_lookup_table( L, -1, nullptr);
2015 lua_pop( L, 1); // settings M 2015 lua_pop( L, 1); // settings M
2016 } 2016 }
2017 lua_pop( L, 1); // settings 2017 lua_pop( L, 1); // settings