diff options
Diffstat (limited to 'src/lanes.cpp')
-rw-r--r-- | src/lanes.cpp | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp index d97a539..fa69656 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -147,12 +147,12 @@ struct s_Linda; | |||
147 | /* | 147 | /* |
148 | * Push a table stored in registry onto Lua stack. | 148 | * Push a table stored in registry onto Lua stack. |
149 | * | 149 | * |
150 | * If there is no existing table, create one if 'create' is TRUE. | 150 | * If there is no existing table, create one if 'create' is true. |
151 | * | 151 | * |
152 | * Returns: TRUE if a table was pushed | 152 | * Returns: true if a table was pushed |
153 | * FALSE if no table found, not created, and nothing pushed | 153 | * false if no table found, not created, and nothing pushed |
154 | */ | 154 | */ |
155 | static bool_t push_registry_table( lua_State* L, UniqueKey key, bool_t create) | 155 | static bool push_registry_table( lua_State* L, UniqueKey key, bool create) |
156 | { | 156 | { |
157 | STACK_GROW( L, 3); | 157 | STACK_GROW( L, 3); |
158 | STACK_CHECK( L, 0); | 158 | STACK_CHECK( L, 0); |
@@ -164,14 +164,14 @@ static bool_t push_registry_table( lua_State* L, UniqueKey key, bool_t create) | |||
164 | 164 | ||
165 | if( !create) | 165 | if( !create) |
166 | { | 166 | { |
167 | return FALSE; | 167 | return false; |
168 | } | 168 | } |
169 | 169 | ||
170 | lua_newtable( L); // t | 170 | lua_newtable( L); // t |
171 | REGISTRY_SET( L, key, lua_pushvalue( L, -2)); | 171 | REGISTRY_SET( L, key, lua_pushvalue( L, -2)); |
172 | } | 172 | } |
173 | STACK_END( L, 1); | 173 | STACK_END( L, 1); |
174 | return TRUE; // table pushed | 174 | return true; // table pushed |
175 | } | 175 | } |
176 | 176 | ||
177 | #if HAVE_LANE_TRACKING() | 177 | #if HAVE_LANE_TRACKING() |
@@ -200,9 +200,9 @@ static void tracking_add( Lane* s) | |||
200 | /* | 200 | /* |
201 | * A free-running lane has ended; remove it from tracking chain | 201 | * A free-running lane has ended; remove it from tracking chain |
202 | */ | 202 | */ |
203 | static bool_t tracking_remove( Lane* s) | 203 | static bool tracking_remove( Lane* s) |
204 | { | 204 | { |
205 | bool_t found = FALSE; | 205 | bool found{ false }; |
206 | MUTEX_LOCK( &s->U->tracking_cs); | 206 | MUTEX_LOCK( &s->U->tracking_cs); |
207 | { | 207 | { |
208 | // Make sure (within the MUTEX) that we actually are in the chain | 208 | // Make sure (within the MUTEX) that we actually are in the chain |
@@ -219,7 +219,7 @@ static bool_t tracking_remove( Lane* s) | |||
219 | { | 219 | { |
220 | *ref = s->tracking_next; | 220 | *ref = s->tracking_next; |
221 | s->tracking_next = nullptr; | 221 | s->tracking_next = nullptr; |
222 | found = TRUE; | 222 | found = true; |
223 | break; | 223 | break; |
224 | } | 224 | } |
225 | ref = (Lane**) &((*ref)->tracking_next); | 225 | ref = (Lane**) &((*ref)->tracking_next); |
@@ -278,7 +278,7 @@ LUAG_FUNC( set_finalizer) | |||
278 | luaL_argcheck( L, lua_isfunction( L, 1), 1, "finalizer should be a function"); | 278 | luaL_argcheck( L, lua_isfunction( L, 1), 1, "finalizer should be a function"); |
279 | luaL_argcheck( L, lua_gettop( L) == 1, 1, "too many arguments"); | 279 | luaL_argcheck( L, lua_gettop( L) == 1, 1, "too many arguments"); |
280 | // Get the current finalizer table (if any) | 280 | // Get the current finalizer table (if any) |
281 | push_registry_table( L, FINALIZER_REGKEY, TRUE /*do create if none*/); // finalizer {finalisers} | 281 | push_registry_table( L, FINALIZER_REGKEY, true /*do create if none*/); // finalizer {finalisers} |
282 | STACK_GROW( L, 2); | 282 | STACK_GROW( L, 2); |
283 | lua_pushinteger( L, lua_rawlen( L, -1) + 1); // finalizer {finalisers} idx | 283 | lua_pushinteger( L, lua_rawlen( L, -1) + 1); // finalizer {finalisers} idx |
284 | lua_pushvalue( L, 1); // finalizer {finalisers} idx finalizer | 284 | lua_pushvalue( L, 1); // finalizer {finalisers} idx finalizer |
@@ -309,7 +309,7 @@ static int run_finalizers( lua_State* L, int lua_rc) | |||
309 | int n; | 309 | int n; |
310 | int err_handler_index = 0; | 310 | int err_handler_index = 0; |
311 | int rc = LUA_OK; // ... | 311 | int rc = LUA_OK; // ... |
312 | if( !push_registry_table( L, FINALIZER_REGKEY, FALSE)) // ... finalizers? | 312 | if( !push_registry_table( L, FINALIZER_REGKEY, false)) // ... finalizers? |
313 | { | 313 | { |
314 | return 0; // no finalizers | 314 | return 0; // no finalizers |
315 | } | 315 | } |
@@ -406,9 +406,9 @@ static void selfdestruct_add( Lane* s) | |||
406 | /* | 406 | /* |
407 | * A free-running lane has ended; remove it from selfdestruct chain | 407 | * A free-running lane has ended; remove it from selfdestruct chain |
408 | */ | 408 | */ |
409 | static bool_t selfdestruct_remove( Lane* s) | 409 | static bool selfdestruct_remove( Lane* s) |
410 | { | 410 | { |
411 | bool_t found = FALSE; | 411 | bool found{ false }; |
412 | MUTEX_LOCK( &s->U->selfdestruct_cs); | 412 | MUTEX_LOCK( &s->U->selfdestruct_cs); |
413 | { | 413 | { |
414 | // Make sure (within the MUTEX) that we actually are in the chain | 414 | // Make sure (within the MUTEX) that we actually are in the chain |
@@ -427,7 +427,7 @@ static bool_t selfdestruct_remove( Lane* s) | |||
427 | s->selfdestruct_next = nullptr; | 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; |
431 | break; | 431 | break; |
432 | } | 432 | } |
433 | ref = (Lane**) &((*ref)->selfdestruct_next); | 433 | ref = (Lane**) &((*ref)->selfdestruct_next); |
@@ -456,9 +456,9 @@ static int selfdestruct_gc( lua_State* L) | |||
456 | while( s != SELFDESTRUCT_END) | 456 | while( s != SELFDESTRUCT_END) |
457 | { | 457 | { |
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 const 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 != nullptr) | 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... |
@@ -653,10 +653,9 @@ static DECLARE_CONST_UNIQUE_KEY( EXTENDED_STACKTRACE_REGKEY, 0x2357c69a7c92c936) | |||
653 | 653 | ||
654 | LUAG_FUNC( set_error_reporting) | 654 | LUAG_FUNC( set_error_reporting) |
655 | { | 655 | { |
656 | bool_t equal; | ||
657 | luaL_checktype( L, 1, LUA_TSTRING); | 656 | luaL_checktype( L, 1, LUA_TSTRING); |
658 | lua_pushliteral( L, "extended"); | 657 | lua_pushliteral( L, "extended"); |
659 | equal = lua_rawequal( L, -1, 1); | 658 | int equal = lua_rawequal( L, -1, 1); |
660 | lua_pop( L, 1); | 659 | lua_pop( L, 1); |
661 | if( equal) | 660 | if( equal) |
662 | { | 661 | { |
@@ -678,7 +677,6 @@ static int lane_error( lua_State* L) | |||
678 | { | 677 | { |
679 | lua_Debug ar; | 678 | lua_Debug ar; |
680 | int n; | 679 | int n; |
681 | bool_t extended; | ||
682 | 680 | ||
683 | // error message (any type) | 681 | // error message (any type) |
684 | STACK_CHECK_ABS( L, 1); // some_error | 682 | STACK_CHECK_ABS( L, 1); // some_error |
@@ -692,7 +690,7 @@ static int lane_error( lua_State* L) | |||
692 | 690 | ||
693 | STACK_GROW( L, 3); | 691 | STACK_GROW( L, 3); |
694 | REGISTRY_GET( L, EXTENDED_STACKTRACE_REGKEY); // some_error basic|extended | 692 | REGISTRY_GET( L, EXTENDED_STACKTRACE_REGKEY); // some_error basic|extended |
695 | extended = lua_toboolean( L, -1); | 693 | bool const extended{ lua_toboolean(L, -1) ? true : false}; |
696 | lua_pop( L, 1); // some_error | 694 | lua_pop( L, 1); // some_error |
697 | 695 | ||
698 | // Place stack trace at 'registry[lane_error]' for the 'lua_pcall()' | 696 | // Place stack trace at 'registry[lane_error]' for the 'lua_pcall()' |
@@ -977,7 +975,7 @@ static THREAD_RETURN_T THREAD_CALLCONV lane_main( void* vs) | |||
977 | MUTEX_UNLOCK( &s->done_lock); | 975 | MUTEX_UNLOCK( &s->done_lock); |
978 | #endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR | 976 | #endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR |
979 | } | 977 | } |
980 | THREAD_CLEANUP_POP( FALSE); | 978 | THREAD_CLEANUP_POP( false); |
981 | return 0; // ignored | 979 | return 0; // ignored |
982 | } | 980 | } |
983 | 981 | ||
@@ -1047,7 +1045,7 @@ LUAG_FUNC( lane_new) | |||
1047 | Lane** ud; | 1045 | Lane** ud; |
1048 | 1046 | ||
1049 | char const* libs_str = lua_tostring( L, 2); | 1047 | char const* libs_str = lua_tostring( L, 2); |
1050 | bool_t const have_priority = !lua_isnoneornil( L, 3); | 1048 | bool const have_priority{ !lua_isnoneornil(L, 3) }; |
1051 | int const priority = have_priority ? (int) lua_tointeger( L, 3) : THREAD_PRIO_DEFAULT; | 1049 | int const priority = have_priority ? (int) lua_tointeger( L, 3) : THREAD_PRIO_DEFAULT; |
1052 | uint_t const globals_idx = lua_isnoneornil( L, 4) ? 0 : 4; | 1050 | uint_t const globals_idx = lua_isnoneornil( L, 4) ? 0 : 4; |
1053 | uint_t const package_idx = lua_isnoneornil( L, 5) ? 0 : 5; | 1051 | uint_t const package_idx = lua_isnoneornil( L, 5) ? 0 : 5; |
@@ -1304,7 +1302,7 @@ LUAG_FUNC( lane_new) | |||
1304 | // | 1302 | // |
1305 | LUAG_FUNC( thread_gc) | 1303 | LUAG_FUNC( thread_gc) |
1306 | { | 1304 | { |
1307 | bool_t have_gc_cb = FALSE; | 1305 | bool have_gc_cb{ false }; |
1308 | Lane* s = lua_toLane( L, 1); // ud | 1306 | Lane* s = lua_toLane( L, 1); // ud |
1309 | 1307 | ||
1310 | // if there a gc callback? | 1308 | // if there a gc callback? |
@@ -1315,7 +1313,7 @@ LUAG_FUNC( thread_gc) | |||
1315 | { | 1313 | { |
1316 | lua_remove( L, -2); // ud gc_cb|nil | 1314 | lua_remove( L, -2); // ud gc_cb|nil |
1317 | lua_pushstring( L, s->debug_name); // ud gc_cb name | 1315 | lua_pushstring( L, s->debug_name); // ud gc_cb name |
1318 | have_gc_cb = TRUE; | 1316 | have_gc_cb = true; |
1319 | } | 1317 | } |
1320 | else | 1318 | else |
1321 | { | 1319 | { |
@@ -1427,7 +1425,7 @@ LUAG_FUNC( thread_join) | |||
1427 | double wait_secs = luaL_optnumber( L, 2, -1.0); | 1425 | double wait_secs = luaL_optnumber( L, 2, -1.0); |
1428 | lua_State* L2 = s->L; | 1426 | lua_State* L2 = s->L; |
1429 | int ret; | 1427 | int ret; |
1430 | bool_t done = THREAD_ISNULL( s->thread) || THREAD_WAIT( &s->thread, wait_secs, &s->done_signal, &s->done_lock, &s->status); | 1428 | bool const done{ THREAD_ISNULL(s->thread) || THREAD_WAIT(&s->thread, wait_secs, &s->done_signal, &s->done_lock, &s->status) }; |
1431 | if( !done || !L2) | 1429 | if( !done || !L2) |
1432 | { | 1430 | { |
1433 | STACK_GROW( L, 2); | 1431 | STACK_GROW( L, 2); |
@@ -1486,7 +1484,7 @@ LUAG_FUNC( thread_join) | |||
1486 | 1484 | ||
1487 | default: | 1485 | default: |
1488 | DEBUGSPEW_CODE( fprintf( stderr, "Status: %d\n", s->status)); | 1486 | DEBUGSPEW_CODE( fprintf( stderr, "Status: %d\n", s->status)); |
1489 | ASSERT_L( FALSE); | 1487 | ASSERT_L( false); |
1490 | ret = 0; | 1488 | ret = 0; |
1491 | } | 1489 | } |
1492 | lua_close( L2); | 1490 | lua_close( L2); |
@@ -1532,11 +1530,10 @@ LUAG_FUNC( thread_index) | |||
1532 | } | 1530 | } |
1533 | { | 1531 | { |
1534 | // check if we already fetched the values from the thread or not | 1532 | // check if we already fetched the values from the thread or not |
1535 | bool_t fetched; | ||
1536 | lua_Integer key = lua_tointeger( L, KEY); | 1533 | lua_Integer key = lua_tointeger( L, KEY); |
1537 | lua_pushinteger( L, 0); | 1534 | lua_pushinteger( L, 0); |
1538 | lua_rawget( L, USR); | 1535 | lua_rawget( L, USR); |
1539 | fetched = !lua_isnil( L, -1); | 1536 | bool const fetched{ !lua_isnil(L, -1) }; |
1540 | lua_pop( L, 1); // back to our 2 args + uservalue on the stack | 1537 | lua_pop( L, 1); // back to our 2 args + uservalue on the stack |
1541 | if( !fetched) | 1538 | if( !fetched) |
1542 | { | 1539 | { |
@@ -1820,7 +1817,7 @@ static volatile long s_initCount = 0; | |||
1820 | LUAG_FUNC( configure) | 1817 | LUAG_FUNC( configure) |
1821 | { | 1818 | { |
1822 | Universe* U = universe_get( L); | 1819 | Universe* U = universe_get( L); |
1823 | bool_t const from_master_state = (U == nullptr); | 1820 | bool const from_master_state{ U == nullptr }; |
1824 | char const* name = luaL_checkstring( L, lua_upvalueindex( 1)); | 1821 | char const* name = luaL_checkstring( L, lua_upvalueindex( 1)); |
1825 | _ASSERT_L( L, lua_type( L, 1) == LUA_TTABLE); | 1822 | _ASSERT_L( L, lua_type( L, 1) == LUA_TTABLE); |
1826 | 1823 | ||
@@ -1879,10 +1876,10 @@ LUAG_FUNC( configure) | |||
1879 | lua_setmetatable( L, -2); // settings universe | 1876 | lua_setmetatable( L, -2); // settings universe |
1880 | lua_pop( L, 1); // settings | 1877 | lua_pop( L, 1); // settings |
1881 | lua_getfield( L, 1, "verbose_errors"); // settings verbose_errors | 1878 | lua_getfield( L, 1, "verbose_errors"); // settings verbose_errors |
1882 | U->verboseErrors = lua_toboolean( L, -1); | 1879 | U->verboseErrors = lua_toboolean( L, -1) ? true : false; |
1883 | lua_pop( L, 1); // settings | 1880 | lua_pop( L, 1); // settings |
1884 | lua_getfield( L, 1, "demote_full_userdata"); // settings demote_full_userdata | 1881 | lua_getfield( L, 1, "demote_full_userdata"); // settings demote_full_userdata |
1885 | U->demoteFullUserdata = lua_toboolean( L, -1); | 1882 | U->demoteFullUserdata = lua_toboolean( L, -1) ? true : false; |
1886 | lua_pop( L, 1); // settings | 1883 | lua_pop( L, 1); // settings |
1887 | #if HAVE_LANE_TRACKING() | 1884 | #if HAVE_LANE_TRACKING() |
1888 | MUTEX_INIT( &U->tracking_cs); | 1885 | MUTEX_INIT( &U->tracking_cs); |