diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cancel.cpp | 10 | ||||
-rw-r--r-- | src/cancel.h | 2 | ||||
-rw-r--r-- | src/deep.cpp | 9 | ||||
-rw-r--r-- | src/keeper.cpp | 2 | ||||
-rw-r--r-- | src/lanes.cpp | 59 | ||||
-rw-r--r-- | src/lanes_private.h | 2 | ||||
-rw-r--r-- | src/linda.cpp | 31 | ||||
-rw-r--r-- | src/macros_and_utils.h | 6 | ||||
-rw-r--r-- | src/state.cpp | 4 | ||||
-rw-r--r-- | src/threading.cpp | 48 | ||||
-rw-r--r-- | src/threading.h | 14 | ||||
-rw-r--r-- | src/tools.cpp | 82 | ||||
-rw-r--r-- | src/tools.h | 2 | ||||
-rw-r--r-- | src/universe.h | 4 |
14 files changed, 131 insertions, 144 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp index 20c30f8..0f22550 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp | |||
@@ -50,7 +50,7 @@ THE SOFTWARE. | |||
50 | * Called by cancellation hooks and/or pending Linda operations (because then | 50 | * Called by cancellation hooks and/or pending Linda operations (because then |
51 | * the check won't affect performance). | 51 | * the check won't affect performance). |
52 | * | 52 | * |
53 | * Returns TRUE if any locks are to be exited, and 'cancel_error()' called, | 53 | * Returns CANCEL_SOFT/HARD if any locks are to be exited, and 'cancel_error()' called, |
54 | * to make execution of the lane end. | 54 | * to make execution of the lane end. |
55 | */ | 55 | */ |
56 | static inline enum e_cancel_request cancel_test( lua_State* L) | 56 | static inline enum e_cancel_request cancel_test( lua_State* L) |
@@ -112,7 +112,7 @@ static void cancel_hook( lua_State* L, lua_Debug* ar) | |||
112 | 112 | ||
113 | // ################################################################################################ | 113 | // ################################################################################################ |
114 | 114 | ||
115 | static cancel_result thread_cancel_soft( Lane* s, double secs_, bool_t wake_lindas_) | 115 | static cancel_result thread_cancel_soft( Lane* s, double secs_, bool wake_lindas_) |
116 | { | 116 | { |
117 | s->cancel_request = CANCEL_SOFT; // it's now signaled to stop | 117 | s->cancel_request = CANCEL_SOFT; // it's now signaled to stop |
118 | // negative timeout: we don't want to truly abort the lane, we just want it to react to cancel_test() on its own | 118 | // negative timeout: we don't want to truly abort the lane, we just want it to react to cancel_test() on its own |
@@ -130,7 +130,7 @@ static cancel_result thread_cancel_soft( Lane* s, double secs_, bool_t wake_lind | |||
130 | 130 | ||
131 | // ################################################################################################ | 131 | // ################################################################################################ |
132 | 132 | ||
133 | static cancel_result thread_cancel_hard( lua_State* L, Lane* s, double secs_, bool_t force_, double waitkill_timeout_) | 133 | static cancel_result thread_cancel_hard( lua_State* L, Lane* s, double secs_, bool force_, double waitkill_timeout_) |
134 | { | 134 | { |
135 | cancel_result result; | 135 | cancel_result result; |
136 | 136 | ||
@@ -175,7 +175,7 @@ static cancel_result thread_cancel_hard( lua_State* L, Lane* s, double secs_, bo | |||
175 | 175 | ||
176 | // ################################################################################################ | 176 | // ################################################################################################ |
177 | 177 | ||
178 | cancel_result thread_cancel( lua_State* L, Lane* s, CancelOp op_, double secs_, bool_t force_, double waitkill_timeout_) | 178 | cancel_result thread_cancel( lua_State* L, Lane* s, CancelOp op_, double secs_, bool force_, double waitkill_timeout_) |
179 | { | 179 | { |
180 | // remember that lanes are not transferable: only one thread can cancel a lane, so no multithreading issue here | 180 | // remember that lanes are not transferable: only one thread can cancel a lane, so no multithreading issue here |
181 | // We can read 's->status' without locks, but not wait for it (if Posix no PTHREAD_TIMEDJOIN) | 181 | // We can read 's->status' without locks, but not wait for it (if Posix no PTHREAD_TIMEDJOIN) |
@@ -276,7 +276,7 @@ LUAG_FUNC( thread_cancel) | |||
276 | } | 276 | } |
277 | 277 | ||
278 | { | 278 | { |
279 | bool_t force = lua_toboolean( L, 2); // FALSE if nothing there | 279 | bool const force = lua_toboolean( L, 2) ? true : false; // false if nothing there |
280 | double forcekill_timeout = luaL_optnumber( L, 3, 0.0); | 280 | double forcekill_timeout = luaL_optnumber( L, 3, 0.0); |
281 | 281 | ||
282 | switch( thread_cancel( L, s, op, secs, force, forcekill_timeout)) | 282 | switch( thread_cancel( L, s, op, secs, force, forcekill_timeout)) |
diff --git a/src/cancel.h b/src/cancel.h index bd6a1d0..e5dfe23 100644 --- a/src/cancel.h +++ b/src/cancel.h | |||
@@ -51,7 +51,7 @@ static DECLARE_CONST_UNIQUE_KEY(CANCEL_ERROR, 0xe97d41626cc97577); // 'cancel_er | |||
51 | // crc64/we of string "CANCEL_TEST_KEY" generated at http://www.nitrxgen.net/hashgen/ | 51 | // crc64/we of string "CANCEL_TEST_KEY" generated at http://www.nitrxgen.net/hashgen/ |
52 | static DECLARE_CONST_UNIQUE_KEY(CANCEL_TEST_KEY, 0xe66f5960c57d133a); // used as registry key | 52 | static DECLARE_CONST_UNIQUE_KEY(CANCEL_TEST_KEY, 0xe66f5960c57d133a); // used as registry key |
53 | 53 | ||
54 | cancel_result thread_cancel( lua_State* L, Lane* s, CancelOp op_, double secs_, bool_t force_, double waitkill_timeout_); | 54 | cancel_result thread_cancel( lua_State* L, Lane* s, CancelOp op_, double secs_, bool force_, double waitkill_timeout_); |
55 | 55 | ||
56 | static inline int cancel_error( lua_State* L) | 56 | static inline int cancel_error( lua_State* L) |
57 | { | 57 | { |
diff --git a/src/deep.cpp b/src/deep.cpp index 58da457..897dc63 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -304,10 +304,9 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in | |||
304 | lua_getfield( L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); // DPC proxy metatable require() "module" _R._LOADED | 304 | lua_getfield( L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); // DPC proxy metatable require() "module" _R._LOADED |
305 | if( lua_istable( L, -1)) | 305 | if( lua_istable( L, -1)) |
306 | { | 306 | { |
307 | bool_t alreadyloaded; | ||
308 | lua_pushvalue( L, -2); // DPC proxy metatable require() "module" _R._LOADED "module" | 307 | lua_pushvalue( L, -2); // DPC proxy metatable require() "module" _R._LOADED "module" |
309 | lua_rawget( L, -2); // DPC proxy metatable require() "module" _R._LOADED module | 308 | lua_rawget( L, -2); // DPC proxy metatable require() "module" _R._LOADED module |
310 | alreadyloaded = lua_toboolean( L, -1); | 309 | int const alreadyloaded = lua_toboolean( L, -1); |
311 | if( !alreadyloaded) // not loaded | 310 | if( !alreadyloaded) // not loaded |
312 | { | 311 | { |
313 | int require_result; | 312 | int require_result; |
@@ -450,7 +449,7 @@ void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index) | |||
450 | * the id function of the copied value, or NULL for non-deep userdata | 449 | * the id function of the copied value, or NULL for non-deep userdata |
451 | * (not copied) | 450 | * (not copied) |
452 | */ | 451 | */ |
453 | bool_t copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) | 452 | bool copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) |
454 | { | 453 | { |
455 | char const* errmsg; | 454 | char const* errmsg; |
456 | luaG_IdFunction idfunc = get_idfunc( L, i, mode_); | 455 | luaG_IdFunction idfunc = get_idfunc( L, i, mode_); |
@@ -458,7 +457,7 @@ bool_t copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, ui | |||
458 | 457 | ||
459 | if( idfunc == NULL) | 458 | if( idfunc == NULL) |
460 | { | 459 | { |
461 | return FALSE; // not a deep userdata | 460 | return false; // not a deep userdata |
462 | } | 461 | } |
463 | 462 | ||
464 | STACK_CHECK( L, 0); | 463 | STACK_CHECK( L, 0); |
@@ -497,5 +496,5 @@ bool_t copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, ui | |||
497 | lua_State* errL = (mode_ == eLM_FromKeeper) ? L2 : L; | 496 | lua_State* errL = (mode_ == eLM_FromKeeper) ? L2 : L; |
498 | luaL_error( errL, errmsg); | 497 | luaL_error( errL, errmsg); |
499 | } | 498 | } |
500 | return TRUE; | 499 | return true; |
501 | } \ No newline at end of file | 500 | } \ No newline at end of file |
diff --git a/src/keeper.cpp b/src/keeper.cpp index 10fba2b..1e344f2 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp | |||
@@ -397,7 +397,7 @@ int keepercall_limit( lua_State* L) | |||
397 | //out: true or nil | 397 | //out: true or nil |
398 | int keepercall_set( lua_State* L) | 398 | int keepercall_set( lua_State* L) |
399 | { | 399 | { |
400 | bool_t should_wake_writers = FALSE; | 400 | bool should_wake_writers{ false }; |
401 | STACK_GROW( L, 6); | 401 | STACK_GROW( L, 6); |
402 | 402 | ||
403 | // retrieve fifos associated with the linda | 403 | // retrieve fifos associated with the linda |
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); |
diff --git a/src/lanes_private.h b/src/lanes_private.h index f0d01ac..27635fa 100644 --- a/src/lanes_private.h +++ b/src/lanes_private.h | |||
@@ -39,7 +39,7 @@ struct s_Lane | |||
39 | 39 | ||
40 | volatile enum e_cancel_request cancel_request; | 40 | volatile enum e_cancel_request cancel_request; |
41 | // | 41 | // |
42 | // M: sets to FALSE, flags TRUE for cancel request | 42 | // M: sets to false, flags true for cancel request |
43 | // S: reads to see if cancel is requested | 43 | // S: reads to see if cancel is requested |
44 | 44 | ||
45 | #if THREADWAIT_METHOD == THREADWAIT_CONDVAR | 45 | #if THREADWAIT_METHOD == THREADWAIT_CONDVAR |
diff --git a/src/linda.cpp b/src/linda.cpp index 5832f22..fa27871 100644 --- a/src/linda.cpp +++ b/src/linda.cpp | |||
@@ -121,12 +121,11 @@ LUAG_FUNC( linda_protected_call) | |||
121 | LUAG_FUNC( linda_send) | 121 | LUAG_FUNC( linda_send) |
122 | { | 122 | { |
123 | struct s_Linda* linda = lua_toLinda( L, 1); | 123 | struct s_Linda* linda = lua_toLinda( L, 1); |
124 | bool_t ret = FALSE; | 124 | bool ret{ false }; |
125 | enum e_cancel_request cancel = CANCEL_NONE; | 125 | enum e_cancel_request cancel = CANCEL_NONE; |
126 | int pushed; | 126 | int pushed; |
127 | time_d timeout = -1.0; | 127 | time_d timeout = -1.0; |
128 | uint_t key_i = 2; // index of first key, if timeout not there | 128 | uint_t key_i = 2; // index of first key, if timeout not there |
129 | bool_t as_nil_sentinel; // if not NULL, send() will silently send a single nil if nothing is provided | ||
130 | 129 | ||
131 | if( lua_type( L, 2) == LUA_TNUMBER) // we don't want to use lua_isnumber() because of autocoercion | 130 | if( lua_type( L, 2) == LUA_TNUMBER) // we don't want to use lua_isnumber() because of autocoercion |
132 | { | 131 | { |
@@ -138,7 +137,7 @@ LUAG_FUNC( linda_send) | |||
138 | ++ key_i; | 137 | ++ key_i; |
139 | } | 138 | } |
140 | 139 | ||
141 | as_nil_sentinel = equal_unique_key( L, key_i, NIL_SENTINEL); | 140 | bool const as_nil_sentinel{ equal_unique_key(L, key_i, NIL_SENTINEL) };// if not nullptr, send() will silently send a single nil if nothing is provided |
142 | if( as_nil_sentinel) | 141 | if( as_nil_sentinel) |
143 | { | 142 | { |
144 | // the real key to send data to is after the NIL_SENTINEL marker | 143 | // the real key to send data to is after the NIL_SENTINEL marker |
@@ -168,13 +167,12 @@ LUAG_FUNC( linda_send) | |||
168 | keeper_toggle_nil_sentinels( L, key_i + 1, eLM_ToKeeper); | 167 | keeper_toggle_nil_sentinels( L, key_i + 1, eLM_ToKeeper); |
169 | 168 | ||
170 | { | 169 | { |
171 | bool_t try_again = TRUE; | ||
172 | Lane* const s = get_lane_from_registry( L); | 170 | Lane* const s = get_lane_from_registry( L); |
173 | Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); | 171 | Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); |
174 | lua_State* KL = K ? K->L : nullptr; // need to do this for 'STACK_CHECK' | 172 | lua_State* KL = K ? K->L : nullptr; // need to do this for 'STACK_CHECK' |
175 | if( KL == nullptr) return 0; | 173 | if( KL == nullptr) return 0; |
176 | STACK_CHECK( KL, 0); | 174 | STACK_CHECK( KL, 0); |
177 | for( ;;) | 175 | for(bool try_again{ true };;) |
178 | { | 176 | { |
179 | if( s != nullptr) | 177 | if( s != nullptr) |
180 | { | 178 | { |
@@ -196,7 +194,7 @@ LUAG_FUNC( linda_send) | |||
196 | } | 194 | } |
197 | ASSERT_L( pushed == 1); | 195 | ASSERT_L( pushed == 1); |
198 | 196 | ||
199 | ret = lua_toboolean( L, -1); | 197 | ret = lua_toboolean( L, -1) ? true : false; |
200 | lua_pop( L, 1); | 198 | lua_pop( L, 1); |
201 | 199 | ||
202 | if( ret) | 200 | if( ret) |
@@ -328,11 +326,10 @@ LUAG_FUNC( linda_receive) | |||
328 | } | 326 | } |
329 | 327 | ||
330 | { | 328 | { |
331 | bool_t try_again = TRUE; | ||
332 | Lane* const s = get_lane_from_registry( L); | 329 | Lane* const s = get_lane_from_registry( L); |
333 | Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); | 330 | Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); |
334 | if( K == nullptr) return 0; | 331 | if( K == nullptr) return 0; |
335 | for( ;;) | 332 | for (bool try_again{ true };;) |
336 | { | 333 | { |
337 | if( s != nullptr) | 334 | if( s != nullptr) |
338 | { | 335 | { |
@@ -425,7 +422,7 @@ LUAG_FUNC( linda_set) | |||
425 | { | 422 | { |
426 | struct s_Linda* const linda = lua_toLinda( L, 1); | 423 | struct s_Linda* const linda = lua_toLinda( L, 1); |
427 | int pushed; | 424 | int pushed; |
428 | bool_t has_value = lua_gettop( L) > 2; | 425 | bool const has_value{ lua_gettop(L) > 2 }; |
429 | 426 | ||
430 | // make sure the key is of a valid type (throws an error if not the case) | 427 | // make sure the key is of a valid type (throws an error if not the case) |
431 | check_key_types( L, 2, 2); | 428 | check_key_types( L, 2, 2); |
@@ -647,7 +644,7 @@ LUAG_FUNC( linda_deep) | |||
647 | * Useful for concatenation or debugging purposes | 644 | * Useful for concatenation or debugging purposes |
648 | */ | 645 | */ |
649 | 646 | ||
650 | static int linda_tostring( lua_State* L, int idx_, bool_t opt_) | 647 | static int linda_tostring( lua_State* L, int idx_, bool opt_) |
651 | { | 648 | { |
652 | struct s_Linda* linda = (struct s_Linda*) luaG_todeep( L, linda_id, idx_); | 649 | struct s_Linda* linda = (struct s_Linda*) luaG_todeep( L, linda_id, idx_); |
653 | if( !opt_) | 650 | if( !opt_) |
@@ -670,7 +667,7 @@ static int linda_tostring( lua_State* L, int idx_, bool_t opt_) | |||
670 | 667 | ||
671 | LUAG_FUNC( linda_tostring) | 668 | LUAG_FUNC( linda_tostring) |
672 | { | 669 | { |
673 | return linda_tostring( L, 1, FALSE); | 670 | return linda_tostring( L, 1, false); |
674 | } | 671 | } |
675 | 672 | ||
676 | 673 | ||
@@ -683,16 +680,16 @@ LUAG_FUNC( linda_tostring) | |||
683 | */ | 680 | */ |
684 | LUAG_FUNC( linda_concat) | 681 | LUAG_FUNC( linda_concat) |
685 | { // linda1? linda2? | 682 | { // linda1? linda2? |
686 | bool_t atLeastOneLinda = FALSE; | 683 | bool atLeastOneLinda{ false }; |
687 | // Lua semantics enforce that one of the 2 arguments is a Linda, but not necessarily both. | 684 | // Lua semantics enforce that one of the 2 arguments is a Linda, but not necessarily both. |
688 | if( linda_tostring( L, 1, TRUE)) | 685 | if( linda_tostring( L, 1, true)) |
689 | { | 686 | { |
690 | atLeastOneLinda = TRUE; | 687 | atLeastOneLinda = true; |
691 | lua_replace( L, 1); | 688 | lua_replace( L, 1); |
692 | } | 689 | } |
693 | if( linda_tostring( L, 2, TRUE)) | 690 | if( linda_tostring( L, 2, true)) |
694 | { | 691 | { |
695 | atLeastOneLinda = TRUE; | 692 | atLeastOneLinda = true; |
696 | lua_replace( L, 2); | 693 | lua_replace( L, 2); |
697 | } | 694 | } |
698 | if( !atLeastOneLinda) // should not be possible | 695 | if( !atLeastOneLinda) // should not be possible |
@@ -727,7 +724,7 @@ LUAG_FUNC( linda_towatch) | |||
727 | if( pushed == 0) | 724 | if( pushed == 0) |
728 | { | 725 | { |
729 | // if the linda is empty, don't return nil | 726 | // if the linda is empty, don't return nil |
730 | pushed = linda_tostring( L, 1, FALSE); | 727 | pushed = linda_tostring( L, 1, false); |
731 | } | 728 | } |
732 | return pushed; | 729 | return pushed; |
733 | } | 730 | } |
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index 5377477..8a4ffb3 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h | |||
@@ -41,7 +41,7 @@ extern char const* debugspew_indent; | |||
41 | int const L##_delta = offset_; \ | 41 | int const L##_delta = offset_; \ |
42 | if( (L##_delta < 0) || (lua_gettop( L) < L##_delta)) \ | 42 | if( (L##_delta < 0) || (lua_gettop( L) < L##_delta)) \ |
43 | { \ | 43 | { \ |
44 | assert( FALSE); \ | 44 | assert( false); \ |
45 | (void) luaL_error( L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop( L), L##_delta, __FILE__, __LINE__); \ | 45 | (void) luaL_error( L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop( L), L##_delta, __FILE__, __LINE__); \ |
46 | } \ | 46 | } \ |
47 | int const L##_oldtop = lua_gettop( L) - L##_delta | 47 | int const L##_oldtop = lua_gettop( L) - L##_delta |
@@ -51,7 +51,7 @@ extern char const* debugspew_indent; | |||
51 | int const L##_pos = offset_; \ | 51 | int const L##_pos = offset_; \ |
52 | if( lua_gettop( L) < L##_pos) \ | 52 | if( lua_gettop( L) < L##_pos) \ |
53 | { \ | 53 | { \ |
54 | assert( FALSE); \ | 54 | assert( false); \ |
55 | (void) luaL_error( L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop( L), L##_pos, __FILE__, __LINE__); \ | 55 | (void) luaL_error( L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop( L), L##_pos, __FILE__, __LINE__); \ |
56 | } \ | 56 | } \ |
57 | int const L##_oldtop = 0 | 57 | int const L##_oldtop = 0 |
@@ -63,7 +63,7 @@ extern char const* debugspew_indent; | |||
63 | int stack_check_b = (change); \ | 63 | int stack_check_b = (change); \ |
64 | if( stack_check_a != stack_check_b) \ | 64 | if( stack_check_a != stack_check_b) \ |
65 | { \ | 65 | { \ |
66 | assert( FALSE); \ | 66 | assert( false); \ |
67 | luaL_error( L, "STACK ASSERT failed (%d not %d): %s:%d", stack_check_a, stack_check_b, __FILE__, __LINE__); \ | 67 | luaL_error( L, "STACK ASSERT failed (%d not %d): %s:%d", stack_check_a, stack_check_b, __FILE__, __LINE__); \ |
68 | } \ | 68 | } \ |
69 | } while( 0) | 69 | } while( 0) |
diff --git a/src/state.cpp b/src/state.cpp index 85ad31e..2213297 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -174,13 +174,13 @@ static void open1lib( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, char con | |||
174 | name_ = libs[i].name; // note that the provided name_ doesn't necessarily ends with '\0', hence len_ | 174 | name_ = libs[i].name; // note that the provided name_ doesn't necessarily ends with '\0', hence len_ |
175 | if( libfunc != NULL) | 175 | if( libfunc != NULL) |
176 | { | 176 | { |
177 | bool_t const isLanesCore = (libfunc == require_lanes_core) ? TRUE : FALSE; // don't want to create a global for "lanes.core" | 177 | bool const isLanesCore{ libfunc == require_lanes_core }; // don't want to create a global for "lanes.core" |
178 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening %.*s library\n" INDENT_END, (int) len_, name_)); | 178 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening %.*s library\n" INDENT_END, (int) len_, name_)); |
179 | STACK_CHECK( L, 0); | 179 | STACK_CHECK( L, 0); |
180 | // open the library as if through require(), and create a global as well if necessary (the library table is left on the stack) | 180 | // open the library as if through require(), and create a global as well if necessary (the library table is left on the stack) |
181 | luaL_requiref( L, name_, libfunc, !isLanesCore); | 181 | luaL_requiref( L, name_, libfunc, !isLanesCore); |
182 | // lanes.core doesn't declare a global, so scan it here and now | 182 | // lanes.core doesn't declare a global, so scan it here and now |
183 | if( isLanesCore == TRUE) | 183 | if( isLanesCore == true) |
184 | { | 184 | { |
185 | populate_func_lookup_table( L, -1, name_); | 185 | populate_func_lookup_table( L, -1, name_); |
186 | } | 186 | } |
diff --git a/src/threading.cpp b/src/threading.cpp index 2464d03..4f3cbc8 100644 --- a/src/threading.cpp +++ b/src/threading.cpp | |||
@@ -68,7 +68,7 @@ THE SOFTWARE. | |||
68 | /* Linux needs to check, whether it's been run as root | 68 | /* Linux needs to check, whether it's been run as root |
69 | */ | 69 | */ |
70 | #ifdef PLATFORM_LINUX | 70 | #ifdef PLATFORM_LINUX |
71 | volatile bool_t sudo; | 71 | volatile bool sudo; |
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | #ifdef PLATFORM_OSX | 74 | #ifdef PLATFORM_OSX |
@@ -271,12 +271,12 @@ static void prepare_timeout( struct timespec *ts, time_d abs_secs ) { | |||
271 | #if _WIN32_WINNT < 0x0600 // CONDITION_VARIABLE aren't available | 271 | #if _WIN32_WINNT < 0x0600 // CONDITION_VARIABLE aren't available |
272 | // | 272 | // |
273 | void MUTEX_INIT( MUTEX_T *ref ) { | 273 | void MUTEX_INIT( MUTEX_T *ref ) { |
274 | *ref= CreateMutex( NULL /*security attr*/, FALSE /*not locked*/, NULL ); | 274 | *ref= CreateMutex( nullptr /*security attr*/, false /*not locked*/, nullptr ); |
275 | if (!ref) FAIL( "CreateMutex", GetLastError() ); | 275 | if (!ref) FAIL( "CreateMutex", GetLastError() ); |
276 | } | 276 | } |
277 | void MUTEX_FREE( MUTEX_T *ref ) { | 277 | void MUTEX_FREE( MUTEX_T *ref ) { |
278 | if (!CloseHandle(*ref)) FAIL( "CloseHandle (mutex)", GetLastError() ); | 278 | if (!CloseHandle(*ref)) FAIL( "CloseHandle (mutex)", GetLastError() ); |
279 | *ref= NULL; | 279 | *ref= nullptr; |
280 | } | 280 | } |
281 | void MUTEX_LOCK( MUTEX_T *ref ) | 281 | void MUTEX_LOCK( MUTEX_T *ref ) |
282 | { | 282 | { |
@@ -352,7 +352,7 @@ void THREAD_SET_AFFINITY( unsigned int aff) | |||
352 | } | 352 | } |
353 | } | 353 | } |
354 | 354 | ||
355 | bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | 355 | bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs) |
356 | { | 356 | { |
357 | DWORD ms = (secs<0.0) ? INFINITE : (DWORD)((secs*1000.0)+0.5); | 357 | DWORD ms = (secs<0.0) ? INFINITE : (DWORD)((secs*1000.0)+0.5); |
358 | 358 | ||
@@ -363,10 +363,10 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
363 | // WAIT_TIMEOUT | 363 | // WAIT_TIMEOUT |
364 | // WAIT_FAILED more info via GetLastError() | 364 | // WAIT_FAILED more info via GetLastError() |
365 | 365 | ||
366 | if (rc == WAIT_TIMEOUT) return FALSE; | 366 | if (rc == WAIT_TIMEOUT) return false; |
367 | if( rc !=0) FAIL( "WaitForSingleObject", rc==WAIT_FAILED ? GetLastError() : rc); | 367 | if( rc !=0) FAIL( "WaitForSingleObject", rc==WAIT_FAILED ? GetLastError() : rc); |
368 | *ref= NULL; // thread no longer usable | 368 | *ref= NULL; // thread no longer usable |
369 | return TRUE; | 369 | return true; |
370 | } | 370 | } |
371 | // | 371 | // |
372 | void THREAD_KILL( THREAD_T *ref ) | 372 | void THREAD_KILL( THREAD_T *ref ) |
@@ -420,9 +420,9 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
420 | { | 420 | { |
421 | InitializeCriticalSection( &ref->signalCS); | 421 | InitializeCriticalSection( &ref->signalCS); |
422 | InitializeCriticalSection( &ref->countCS); | 422 | InitializeCriticalSection( &ref->countCS); |
423 | if( 0 == (ref->waitEvent = CreateEvent( 0, TRUE, FALSE, 0))) // manual-reset | 423 | if( 0 == (ref->waitEvent = CreateEvent( 0, true, false, 0))) // manual-reset |
424 | FAIL( "CreateEvent", GetLastError()); | 424 | FAIL( "CreateEvent", GetLastError()); |
425 | if( 0 == (ref->waitDoneEvent = CreateEvent( 0, FALSE, FALSE, 0))) // auto-reset | 425 | if( 0 == (ref->waitDoneEvent = CreateEvent( 0, false, false, 0))) // auto-reset |
426 | FAIL( "CreateEvent", GetLastError()); | 426 | FAIL( "CreateEvent", GetLastError()); |
427 | ref->waitersCount = 0; | 427 | ref->waitersCount = 0; |
428 | } | 428 | } |
@@ -435,7 +435,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
435 | DeleteCriticalSection( &ref->signalCS); | 435 | DeleteCriticalSection( &ref->signalCS); |
436 | } | 436 | } |
437 | 437 | ||
438 | bool_t SIGNAL_WAIT( SIGNAL_T* ref, MUTEX_T* mu_ref, time_d abs_secs) | 438 | bool SIGNAL_WAIT( SIGNAL_T* ref, MUTEX_T* mu_ref, time_d abs_secs) |
439 | { | 439 | { |
440 | DWORD errc; | 440 | DWORD errc; |
441 | DWORD ms; | 441 | DWORD ms; |
@@ -458,7 +458,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
458 | LeaveCriticalSection( &ref->countCS); | 458 | LeaveCriticalSection( &ref->countCS); |
459 | LeaveCriticalSection( &ref->signalCS); | 459 | LeaveCriticalSection( &ref->signalCS); |
460 | 460 | ||
461 | errc = SignalObjectAndWait( *mu_ref, ref->waitEvent, ms, FALSE); | 461 | errc = SignalObjectAndWait( *mu_ref, ref->waitEvent, ms, false); |
462 | 462 | ||
463 | EnterCriticalSection( &ref->countCS); | 463 | EnterCriticalSection( &ref->countCS); |
464 | if( 0 == -- ref->waitersCount) | 464 | if( 0 == -- ref->waitersCount) |
@@ -473,13 +473,13 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
473 | switch( errc) | 473 | switch( errc) |
474 | { | 474 | { |
475 | case WAIT_TIMEOUT: | 475 | case WAIT_TIMEOUT: |
476 | return FALSE; | 476 | return false; |
477 | case WAIT_OBJECT_0: | 477 | case WAIT_OBJECT_0: |
478 | return TRUE; | 478 | return true; |
479 | } | 479 | } |
480 | 480 | ||
481 | FAIL( "SignalObjectAndWait", GetLastError()); | 481 | FAIL( "SignalObjectAndWait", GetLastError()); |
482 | return FALSE; | 482 | return false; |
483 | } | 483 | } |
484 | 484 | ||
485 | void SIGNAL_ALL( SIGNAL_T* ref) | 485 | void SIGNAL_ALL( SIGNAL_T* ref) |
@@ -521,7 +521,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
521 | (void)ref; | 521 | (void)ref; |
522 | } | 522 | } |
523 | 523 | ||
524 | bool_t SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu_ref, time_d abs_secs) | 524 | bool SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu_ref, time_d abs_secs) |
525 | { | 525 | { |
526 | long ms; | 526 | long ms; |
527 | 527 | ||
@@ -544,14 +544,14 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
544 | { | 544 | { |
545 | if( GetLastError() == ERROR_TIMEOUT) | 545 | if( GetLastError() == ERROR_TIMEOUT) |
546 | { | 546 | { |
547 | return FALSE; | 547 | return false; |
548 | } | 548 | } |
549 | else | 549 | else |
550 | { | 550 | { |
551 | FAIL( "SleepConditionVariableCS", GetLastError()); | 551 | FAIL( "SleepConditionVariableCS", GetLastError()); |
552 | } | 552 | } |
553 | } | 553 | } |
554 | return TRUE; | 554 | return true; |
555 | } | 555 | } |
556 | 556 | ||
557 | void SIGNAL_ONE( SIGNAL_T *ref ) | 557 | void SIGNAL_ONE( SIGNAL_T *ref ) |
@@ -620,7 +620,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
620 | * a timed out sleep. A Linda with some other key read, or just because | 620 | * a timed out sleep. A Linda with some other key read, or just because |
621 | * PThread cond vars can wake up unwantedly. | 621 | * PThread cond vars can wake up unwantedly. |
622 | */ | 622 | */ |
623 | bool_t SIGNAL_WAIT( SIGNAL_T *ref, pthread_mutex_t *mu, time_d abs_secs ) { | 623 | bool SIGNAL_WAIT( SIGNAL_T *ref, pthread_mutex_t *mu, time_d abs_secs ) { |
624 | if (abs_secs<0.0) { | 624 | if (abs_secs<0.0) { |
625 | PT_CALL( pthread_cond_wait( ref, mu ) ); // infinite | 625 | PT_CALL( pthread_cond_wait( ref, mu ) ); // infinite |
626 | } else { | 626 | } else { |
@@ -632,10 +632,10 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
632 | 632 | ||
633 | rc= pthread_cond_timedwait( ref, mu, &ts ); | 633 | rc= pthread_cond_timedwait( ref, mu, &ts ); |
634 | 634 | ||
635 | if (rc==ETIMEDOUT) return FALSE; | 635 | if (rc==ETIMEDOUT) return false; |
636 | if (rc) { _PT_FAIL( rc, "pthread_cond_timedwait()", __FILE__, __LINE__ ); } | 636 | if (rc) { _PT_FAIL( rc, "pthread_cond_timedwait()", __FILE__, __LINE__ ); } |
637 | } | 637 | } |
638 | return TRUE; | 638 | return true; |
639 | } | 639 | } |
640 | // | 640 | // |
641 | void SIGNAL_ONE( SIGNAL_T *ref ) { | 641 | void SIGNAL_ONE( SIGNAL_T *ref ) { |
@@ -778,7 +778,7 @@ static int select_prio(int prio /* -3..+3 */) | |||
778 | void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (*func)( void*), void* data, int prio /* -3..+3 */) | 778 | void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (*func)( void*), void* data, int prio /* -3..+3 */) |
779 | { | 779 | { |
780 | pthread_attr_t a; | 780 | pthread_attr_t a; |
781 | bool_t const change_priority = | 781 | bool const change_priority = |
782 | #ifdef PLATFORM_LINUX | 782 | #ifdef PLATFORM_LINUX |
783 | sudo && // only root-privileged process can change priorities | 783 | sudo && // only root-privileged process can change priorities |
784 | #endif | 784 | #endif |
@@ -935,13 +935,13 @@ void THREAD_SET_AFFINITY( unsigned int aff) | |||
935 | * 'mu_ref' is a lock we should use for the waiting; initially unlocked. | 935 | * 'mu_ref' is a lock we should use for the waiting; initially unlocked. |
936 | * Same lock as passed to THREAD_EXIT. | 936 | * Same lock as passed to THREAD_EXIT. |
937 | * | 937 | * |
938 | * Returns TRUE for successful wait, FALSE for timed out | 938 | * Returns true for successful wait, false for timed out |
939 | */ | 939 | */ |
940 | bool_t THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu_ref, volatile enum e_status *st_ref) | 940 | bool THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu_ref, volatile enum e_status *st_ref) |
941 | { | 941 | { |
942 | struct timespec ts_store; | 942 | struct timespec ts_store; |
943 | const struct timespec *timeout= NULL; | 943 | const struct timespec *timeout= NULL; |
944 | bool_t done; | 944 | bool done; |
945 | 945 | ||
946 | // Do timeout counting before the locks | 946 | // Do timeout counting before the locks |
947 | // | 947 | // |
@@ -960,7 +960,7 @@ bool_t THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T * | |||
960 | */ | 960 | */ |
961 | if (!timeout) { | 961 | if (!timeout) { |
962 | PT_CALL( pthread_join( *ref, NULL /*ignore exit value*/ )); | 962 | PT_CALL( pthread_join( *ref, NULL /*ignore exit value*/ )); |
963 | done= TRUE; | 963 | done = true; |
964 | } else { | 964 | } else { |
965 | int rc= PTHREAD_TIMEDJOIN( *ref, NULL, timeout ); | 965 | int rc= PTHREAD_TIMEDJOIN( *ref, NULL, timeout ); |
966 | if ((rc!=0) && (rc!=ETIMEDOUT)) { | 966 | if ((rc!=0) && (rc!=ETIMEDOUT)) { |
diff --git a/src/threading.h b/src/threading.h index 8324bdd..24e0998 100644 --- a/src/threading.h +++ b/src/threading.h | |||
@@ -7,12 +7,6 @@ | |||
7 | */ | 7 | */ |
8 | #include "platform.h" | 8 | #include "platform.h" |
9 | 9 | ||
10 | typedef int bool_t; | ||
11 | #ifndef FALSE | ||
12 | # define FALSE 0 | ||
13 | # define TRUE 1 | ||
14 | #endif | ||
15 | |||
16 | typedef unsigned int uint_t; | 10 | typedef unsigned int uint_t; |
17 | 11 | ||
18 | #include <time.h> | 12 | #include <time.h> |
@@ -165,7 +159,7 @@ time_d now_secs(void); | |||
165 | 159 | ||
166 | time_d SIGNAL_TIMEOUT_PREPARE( double rel_secs ); | 160 | time_d SIGNAL_TIMEOUT_PREPARE( double rel_secs ); |
167 | 161 | ||
168 | bool_t SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu, time_d timeout ); | 162 | bool SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu, time_d timeout ); |
169 | 163 | ||
170 | 164 | ||
171 | /*---=== Threading ===--- | 165 | /*---=== Threading ===--- |
@@ -209,7 +203,7 @@ bool_t SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu, time_d timeout ); | |||
209 | void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (*func)( void*), void* data, int prio /* -3..+3 */); | 203 | void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (*func)( void*), void* data, int prio /* -3..+3 */); |
210 | 204 | ||
211 | # if defined(PLATFORM_LINUX) | 205 | # if defined(PLATFORM_LINUX) |
212 | extern volatile bool_t sudo; | 206 | extern volatile bool sudo; |
213 | # ifdef LINUX_SCHED_RR | 207 | # ifdef LINUX_SCHED_RR |
214 | # define THREAD_PRIO_MIN (sudo ? -3 : 0) | 208 | # define THREAD_PRIO_MIN (sudo ? -3 : 0) |
215 | # else | 209 | # else |
@@ -245,10 +239,10 @@ bool_t SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu, time_d timeout ); | |||
245 | 239 | ||
246 | 240 | ||
247 | #if THREADWAIT_METHOD == THREADWAIT_TIMEOUT | 241 | #if THREADWAIT_METHOD == THREADWAIT_TIMEOUT |
248 | bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs); | 242 | bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs); |
249 | #define THREAD_WAIT( a, b, c, d, e) THREAD_WAIT_IMPL( a, b) | 243 | #define THREAD_WAIT( a, b, c, d, e) THREAD_WAIT_IMPL( a, b) |
250 | #else // THREADWAIT_METHOD == THREADWAIT_CONDVAR | 244 | #else // THREADWAIT_METHOD == THREADWAIT_CONDVAR |
251 | bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs, SIGNAL_T *signal_ref, MUTEX_T *mu_ref, volatile enum e_status *st_ref); | 245 | bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs, SIGNAL_T *signal_ref, MUTEX_T *mu_ref, volatile enum e_status *st_ref); |
252 | #define THREAD_WAIT THREAD_WAIT_IMPL | 246 | #define THREAD_WAIT THREAD_WAIT_IMPL |
253 | #endif // // THREADWAIT_METHOD == THREADWAIT_CONDVAR | 247 | #endif // // THREADWAIT_METHOD == THREADWAIT_CONDVAR |
254 | 248 | ||
diff --git a/src/tools.cpp b/src/tools.cpp index 6f4a06a..e6ebdba 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -48,7 +48,7 @@ THE SOFTWARE. | |||
48 | #include "uniquekey.h" | 48 | #include "uniquekey.h" |
49 | 49 | ||
50 | // functions implemented in deep.c | 50 | // functions implemented in deep.c |
51 | extern bool_t copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_); | 51 | extern bool copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_); |
52 | extern void push_registry_subtable( lua_State* L, UniqueKey key_); | 52 | extern void push_registry_subtable( lua_State* L, UniqueKey key_); |
53 | 53 | ||
54 | DEBUGSPEW_CODE( char const* debugspew_indent = "----+----!----+----!----+----!----+----!----+----!----+----!----+----!----+"); | 54 | DEBUGSPEW_CODE( char const* debugspew_indent = "----+----!----+----!----+----!----+----!----+----!----+----!----+----!----+"); |
@@ -766,14 +766,14 @@ static char const* find_lookup_name( lua_State* L, uint_t i, LookupMode mode_, c | |||
766 | /* | 766 | /* |
767 | * Push a looked-up table, or nothing if we found nothing | 767 | * Push a looked-up table, or nothing if we found nothing |
768 | */ | 768 | */ |
769 | static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) | 769 | static bool lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) |
770 | { | 770 | { |
771 | // get the name of the table we want to send | 771 | // get the name of the table we want to send |
772 | size_t len; | 772 | size_t len; |
773 | char const* fqn = find_lookup_name( L, i, mode_, upName_, &len); | 773 | char const* fqn = find_lookup_name( L, i, mode_, upName_, &len); |
774 | if( NULL == fqn) // name not found, it is some user-created table | 774 | if( NULL == fqn) // name not found, it is some user-created table |
775 | { | 775 | { |
776 | return FALSE; | 776 | return false; |
777 | } | 777 | } |
778 | // push the equivalent table in the destination's stack, retrieved from the lookup table | 778 | // push the equivalent table in the destination's stack, retrieved from the lookup table |
779 | STACK_CHECK( L2, 0); // L // L2 | 779 | STACK_CHECK( L2, 0); // L // L2 |
@@ -782,7 +782,7 @@ static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mo | |||
782 | { | 782 | { |
783 | default: // shouldn't happen, in theory... | 783 | default: // shouldn't happen, in theory... |
784 | (void) luaL_error( L, "internal error: unknown lookup mode"); | 784 | (void) luaL_error( L, "internal error: unknown lookup mode"); |
785 | return FALSE; | 785 | return false; |
786 | 786 | ||
787 | case eLM_ToKeeper: | 787 | case eLM_ToKeeper: |
788 | // push a sentinel closure that holds the lookup name as upvalue | 788 | // push a sentinel closure that holds the lookup name as upvalue |
@@ -803,7 +803,7 @@ static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mo | |||
803 | { | 803 | { |
804 | lua_pop( L2, 2); // | 804 | lua_pop( L2, 2); // |
805 | STACK_MID( L2, 0); | 805 | STACK_MID( L2, 0); |
806 | return FALSE; | 806 | return false; |
807 | } | 807 | } |
808 | else if( !lua_istable( L2, -1)) | 808 | else if( !lua_istable( L2, -1)) |
809 | { | 809 | { |
@@ -822,13 +822,13 @@ static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mo | |||
822 | , fqn | 822 | , fqn |
823 | , to ? to : "main" | 823 | , to ? to : "main" |
824 | ); | 824 | ); |
825 | return FALSE; | 825 | return false; |
826 | } | 826 | } |
827 | lua_remove( L2, -2); // t | 827 | lua_remove( L2, -2); // t |
828 | break; | 828 | break; |
829 | } | 829 | } |
830 | STACK_END( L2, 1); | 830 | STACK_END( L2, 1); |
831 | return TRUE; | 831 | return true; |
832 | } | 832 | } |
833 | 833 | ||
834 | 834 | ||
@@ -839,12 +839,12 @@ static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mo | |||
839 | * | 839 | * |
840 | * Always pushes a table to 'L2'. | 840 | * Always pushes a table to 'L2'. |
841 | * | 841 | * |
842 | * Returns TRUE if the table was cached (no need to fill it!); FALSE if | 842 | * Returns true if the table was cached (no need to fill it!); false if |
843 | * it's a virgin. | 843 | * it's a virgin. |
844 | */ | 844 | */ |
845 | static bool_t push_cached_table( lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i) | 845 | static bool push_cached_table( lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i) |
846 | { | 846 | { |
847 | bool_t not_found_in_cache; // L2 | 847 | bool not_found_in_cache; // L2 |
848 | DECLARE_CONST_UNIQUE_KEY( p, lua_topointer( L, i)); | 848 | DECLARE_CONST_UNIQUE_KEY( p, lua_topointer( L, i)); |
849 | 849 | ||
850 | ASSERT_L( L2_cache_i != 0); | 850 | ASSERT_L( L2_cache_i != 0); |
@@ -854,11 +854,11 @@ static bool_t push_cached_table( lua_State* L2, uint_t L2_cache_i, lua_State* L, | |||
854 | // We don't need to use the from state ('L') in ID since the life span | 854 | // We don't need to use the from state ('L') in ID since the life span |
855 | // is only for the duration of a copy (both states are locked). | 855 | // is only for the duration of a copy (both states are locked). |
856 | // push a light userdata uniquely representing the table | 856 | // push a light userdata uniquely representing the table |
857 | push_unique_key( L2, p); // ... p | 857 | push_unique_key( L2, p); // ... p |
858 | 858 | ||
859 | //fprintf( stderr, "<< ID: %s >>\n", lua_tostring( L2, -1)); | 859 | //fprintf( stderr, "<< ID: %s >>\n", lua_tostring( L2, -1)); |
860 | 860 | ||
861 | lua_rawget( L2, L2_cache_i); // ... {cached|nil} | 861 | lua_rawget( L2, L2_cache_i); // ... {cached|nil} |
862 | not_found_in_cache = lua_isnil( L2, -1); | 862 | not_found_in_cache = lua_isnil( L2, -1); |
863 | if( not_found_in_cache) | 863 | if( not_found_in_cache) |
864 | { | 864 | { |
@@ -1391,7 +1391,7 @@ static void copy_cached_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua | |||
1391 | } | 1391 | } |
1392 | } | 1392 | } |
1393 | 1393 | ||
1394 | static bool_t push_cached_metatable( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum eLookupMode mode_, char const* upName_) | 1394 | static bool push_cached_metatable( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum eLookupMode mode_, char const* upName_) |
1395 | { | 1395 | { |
1396 | STACK_CHECK( L, 0); | 1396 | STACK_CHECK( L, 0); |
1397 | if( lua_getmetatable( L, i)) // ... mt | 1397 | if( lua_getmetatable( L, i)) // ... mt |
@@ -1434,10 +1434,10 @@ static bool_t push_cached_metatable( Universe* U, lua_State* L2, uint_t L2_cache | |||
1434 | lua_pop( L, 1); // ... | 1434 | lua_pop( L, 1); // ... |
1435 | STACK_END( L2, 1); | 1435 | STACK_END( L2, 1); |
1436 | STACK_MID( L, 0); | 1436 | STACK_MID( L, 0); |
1437 | return TRUE; | 1437 | return true; |
1438 | } | 1438 | } |
1439 | STACK_END( L, 0); | 1439 | STACK_END( L, 0); |
1440 | return FALSE; | 1440 | return false; |
1441 | } | 1441 | } |
1442 | 1442 | ||
1443 | static void inter_copy_keyvaluepair( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, enum e_vt vt, LookupMode mode_, char const* upName_) | 1443 | static void inter_copy_keyvaluepair( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, enum e_vt vt, LookupMode mode_, char const* upName_) |
@@ -1510,7 +1510,7 @@ static void inter_copy_keyvaluepair( Universe* U, lua_State* L2, uint_t L2_cache | |||
1510 | */ | 1510 | */ |
1511 | static DECLARE_CONST_UNIQUE_KEY( CLONABLES_CACHE_KEY, 0xD04EE018B3DEE8F5); | 1511 | static DECLARE_CONST_UNIQUE_KEY( CLONABLES_CACHE_KEY, 0xD04EE018B3DEE8F5); |
1512 | 1512 | ||
1513 | static bool_t copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t source_i_, LookupMode mode_, char const* upName_) | 1513 | static bool copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t source_i_, LookupMode mode_, char const* upName_) |
1514 | { | 1514 | { |
1515 | void* const source = lua_touserdata( L, source_i_); | 1515 | void* const source = lua_touserdata( L, source_i_); |
1516 | source_i_ = lua_absindex( L, source_i_); | 1516 | source_i_ = lua_absindex( L, source_i_); |
@@ -1524,7 +1524,7 @@ static bool_t copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_Stat | |||
1524 | if ( !lua_isnil( L2, -1)) | 1524 | if ( !lua_isnil( L2, -1)) |
1525 | { | 1525 | { |
1526 | STACK_MID( L2, 1); | 1526 | STACK_MID( L2, 1); |
1527 | return TRUE; | 1527 | return true; |
1528 | } | 1528 | } |
1529 | else | 1529 | else |
1530 | { | 1530 | { |
@@ -1536,7 +1536,7 @@ static bool_t copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_Stat | |||
1536 | if( !lua_getmetatable( L, source_i_)) // ... mt? | 1536 | if( !lua_getmetatable( L, source_i_)) // ... mt? |
1537 | { | 1537 | { |
1538 | STACK_MID( L, 0); | 1538 | STACK_MID( L, 0); |
1539 | return FALSE; | 1539 | return false; |
1540 | } | 1540 | } |
1541 | 1541 | ||
1542 | // no __lanesclone? -> not clonable | 1542 | // no __lanesclone? -> not clonable |
@@ -1545,7 +1545,7 @@ static bool_t copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_Stat | |||
1545 | { | 1545 | { |
1546 | lua_pop( L, 2); // ... | 1546 | lua_pop( L, 2); // ... |
1547 | STACK_MID( L, 0); | 1547 | STACK_MID( L, 0); |
1548 | return FALSE; | 1548 | return false; |
1549 | } | 1549 | } |
1550 | 1550 | ||
1551 | // we need to copy over the uservalues of the userdata as well | 1551 | // we need to copy over the uservalues of the userdata as well |
@@ -1620,16 +1620,16 @@ static bool_t copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_Stat | |||
1620 | STACK_END( L2, 1); | 1620 | STACK_END( L2, 1); |
1621 | lua_pop( L, 1); // ... | 1621 | lua_pop( L, 1); // ... |
1622 | STACK_END( L, 0); | 1622 | STACK_END( L, 0); |
1623 | return TRUE; | 1623 | return true; |
1624 | } | 1624 | } |
1625 | 1625 | ||
1626 | static bool_t inter_copy_userdata( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_) | 1626 | static bool inter_copy_userdata( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_) |
1627 | { | 1627 | { |
1628 | STACK_CHECK( L, 0); | 1628 | STACK_CHECK( L, 0); |
1629 | STACK_CHECK( L2, 0); | 1629 | STACK_CHECK( L2, 0); |
1630 | if( vt == VT_KEY) | 1630 | if( vt == VT_KEY) |
1631 | { | 1631 | { |
1632 | return FALSE; | 1632 | return false; |
1633 | } | 1633 | } |
1634 | 1634 | ||
1635 | // try clonable userdata first | 1635 | // try clonable userdata first |
@@ -1637,7 +1637,7 @@ static bool_t inter_copy_userdata( Universe* U, lua_State* L2, uint_t L2_cache_i | |||
1637 | { | 1637 | { |
1638 | STACK_MID( L, 0); | 1638 | STACK_MID( L, 0); |
1639 | STACK_MID( L2, 1); | 1639 | STACK_MID( L2, 1); |
1640 | return TRUE; | 1640 | return true; |
1641 | } | 1641 | } |
1642 | 1642 | ||
1643 | STACK_MID( L, 0); | 1643 | STACK_MID( L, 0); |
@@ -1649,7 +1649,7 @@ static bool_t inter_copy_userdata( Universe* U, lua_State* L2, uint_t L2_cache_i | |||
1649 | { | 1649 | { |
1650 | STACK_MID( L, 0); | 1650 | STACK_MID( L, 0); |
1651 | STACK_MID( L2, 1); | 1651 | STACK_MID( L2, 1); |
1652 | return TRUE; | 1652 | return true; |
1653 | } | 1653 | } |
1654 | 1654 | ||
1655 | STACK_MID( L, 0); | 1655 | STACK_MID( L, 0); |
@@ -1668,14 +1668,14 @@ static bool_t inter_copy_userdata( Universe* U, lua_State* L2, uint_t L2_cache_i | |||
1668 | 1668 | ||
1669 | STACK_END( L2, 1); | 1669 | STACK_END( L2, 1); |
1670 | STACK_END( L, 0); | 1670 | STACK_END( L, 0); |
1671 | return TRUE; | 1671 | return true; |
1672 | } | 1672 | } |
1673 | 1673 | ||
1674 | static bool_t inter_copy_function( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t source_i_, enum e_vt vt, LookupMode mode_, char const* upName_) | 1674 | static bool inter_copy_function( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t source_i_, enum e_vt vt, LookupMode mode_, char const* upName_) |
1675 | { | 1675 | { |
1676 | if( vt == VT_KEY) | 1676 | if( vt == VT_KEY) |
1677 | { | 1677 | { |
1678 | return FALSE; | 1678 | return false; |
1679 | } | 1679 | } |
1680 | 1680 | ||
1681 | STACK_CHECK( L, 0); // L (source) // L2 (destination) | 1681 | STACK_CHECK( L, 0); // L (source) // L2 (destination) |
@@ -1699,7 +1699,7 @@ static bool_t inter_copy_function( Universe* U, lua_State* L2, uint_t L2_cache_i | |||
1699 | lua_pop( L, 1); // ... | 1699 | lua_pop( L, 1); // ... |
1700 | STACK_MID( L, 0); | 1700 | STACK_MID( L, 0); |
1701 | STACK_MID( L2, 1); | 1701 | STACK_MID( L2, 1); |
1702 | return TRUE; | 1702 | return true; |
1703 | } | 1703 | } |
1704 | lua_pop( L2, 1); // ... | 1704 | lua_pop( L2, 1); // ... |
1705 | 1705 | ||
@@ -1761,14 +1761,14 @@ static bool_t inter_copy_function( Universe* U, lua_State* L2, uint_t L2_cache_i | |||
1761 | } | 1761 | } |
1762 | STACK_END( L2, 1); | 1762 | STACK_END( L2, 1); |
1763 | STACK_END( L, 0); | 1763 | STACK_END( L, 0); |
1764 | return TRUE; | 1764 | return true; |
1765 | } | 1765 | } |
1766 | 1766 | ||
1767 | static bool_t inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_) | 1767 | static bool inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_) |
1768 | { | 1768 | { |
1769 | if( vt == VT_KEY) | 1769 | if( vt == VT_KEY) |
1770 | { | 1770 | { |
1771 | return FALSE; | 1771 | return false; |
1772 | } | 1772 | } |
1773 | 1773 | ||
1774 | STACK_CHECK( L, 0); | 1774 | STACK_CHECK( L, 0); |
@@ -1782,7 +1782,7 @@ static bool_t inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, l | |||
1782 | if( lookup_table( L2, L, i, mode_, upName_)) | 1782 | if( lookup_table( L2, L, i, mode_, upName_)) |
1783 | { | 1783 | { |
1784 | ASSERT_L( lua_istable( L2, -1) || (lua_tocfunction( L2, -1) == table_lookup_sentinel)); // from lookup datables // can also be table_lookup_sentinel if this is a table we know | 1784 | ASSERT_L( lua_istable( L2, -1) || (lua_tocfunction( L2, -1) == table_lookup_sentinel)); // from lookup datables // can also be table_lookup_sentinel if this is a table we know |
1785 | return TRUE; | 1785 | return true; |
1786 | } | 1786 | } |
1787 | 1787 | ||
1788 | /* Check if we've already copied the same table from 'L' (during this transmission), and | 1788 | /* Check if we've already copied the same table from 'L' (during this transmission), and |
@@ -1797,7 +1797,7 @@ static bool_t inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, l | |||
1797 | if( push_cached_table( L2, L2_cache_i, L, i)) | 1797 | if( push_cached_table( L2, L2_cache_i, L, i)) |
1798 | { | 1798 | { |
1799 | ASSERT_L( lua_istable( L2, -1)); // from cache | 1799 | ASSERT_L( lua_istable( L2, -1)); // from cache |
1800 | return TRUE; | 1800 | return true; |
1801 | } | 1801 | } |
1802 | ASSERT_L( lua_istable( L2, -1)); | 1802 | ASSERT_L( lua_istable( L2, -1)); |
1803 | 1803 | ||
@@ -1821,7 +1821,7 @@ static bool_t inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, l | |||
1821 | } | 1821 | } |
1822 | STACK_END( L2, 1); | 1822 | STACK_END( L2, 1); |
1823 | STACK_END( L, 0); | 1823 | STACK_END( L, 0); |
1824 | return TRUE; | 1824 | return true; |
1825 | } | 1825 | } |
1826 | 1826 | ||
1827 | /* | 1827 | /* |
@@ -1832,11 +1832,11 @@ static bool_t inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, l | |||
1832 | * | 1832 | * |
1833 | * 'i' is an absolute index (no -1, ...) | 1833 | * 'i' is an absolute index (no -1, ...) |
1834 | * | 1834 | * |
1835 | * Returns TRUE if value was pushed, FALSE if its type is non-supported. | 1835 | * Returns true if value was pushed, false if its type is non-supported. |
1836 | */ | 1836 | */ |
1837 | bool_t inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_) | 1837 | bool inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_) |
1838 | { | 1838 | { |
1839 | bool_t ret = TRUE; | 1839 | bool ret{ true }; |
1840 | int val_type = lua_type( L, i); | 1840 | int val_type = lua_type( L, i); |
1841 | static int const pod_mask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); | 1841 | static int const pod_mask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); |
1842 | STACK_GROW( L2, 1); | 1842 | STACK_GROW( L2, 1); |
@@ -1870,7 +1870,7 @@ bool_t inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* | |||
1870 | 1870 | ||
1871 | case LUA_TBOOLEAN: | 1871 | case LUA_TBOOLEAN: |
1872 | { | 1872 | { |
1873 | bool_t v = lua_toboolean( L, i); | 1873 | int const v{ lua_toboolean(L, i) }; |
1874 | DEBUGSPEW_CODE( fprintf( stderr, "%s\n", v ? "true" : "false")); | 1874 | DEBUGSPEW_CODE( fprintf( stderr, "%s\n", v ? "true" : "false")); |
1875 | lua_pushboolean( L2, v); | 1875 | lua_pushboolean( L2, v); |
1876 | } | 1876 | } |
@@ -1921,7 +1921,7 @@ bool_t inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* | |||
1921 | case LUA_TNIL: | 1921 | case LUA_TNIL: |
1922 | if( vt == VT_KEY) | 1922 | if( vt == VT_KEY) |
1923 | { | 1923 | { |
1924 | ret = FALSE; | 1924 | ret = false; |
1925 | break; | 1925 | break; |
1926 | } | 1926 | } |
1927 | lua_pushnil( L2); | 1927 | lua_pushnil( L2); |
@@ -1939,7 +1939,7 @@ bool_t inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* | |||
1939 | 1939 | ||
1940 | case 10: // LuaJIT CDATA | 1940 | case 10: // LuaJIT CDATA |
1941 | case LUA_TTHREAD: | 1941 | case LUA_TTHREAD: |
1942 | ret = FALSE; | 1942 | ret = false; |
1943 | break; | 1943 | break; |
1944 | } | 1944 | } |
1945 | 1945 | ||
@@ -1964,7 +1964,7 @@ int luaG_inter_copy( Universe* U, lua_State* L, lua_State* L2, uint_t n, LookupM | |||
1964 | uint_t i, j; | 1964 | uint_t i, j; |
1965 | char tmpBuf[16]; | 1965 | char tmpBuf[16]; |
1966 | char const* pBuf = U->verboseErrors ? tmpBuf : "?"; | 1966 | char const* pBuf = U->verboseErrors ? tmpBuf : "?"; |
1967 | bool_t copyok = TRUE; | 1967 | bool copyok{ true }; |
1968 | 1968 | ||
1969 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_inter_copy()\n" INDENT_END)); | 1969 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_inter_copy()\n" INDENT_END)); |
1970 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); | 1970 | DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); |
diff --git a/src/tools.h b/src/tools.h index c714837..9214d85 100644 --- a/src/tools.h +++ b/src/tools.h | |||
@@ -29,7 +29,7 @@ enum e_vt | |||
29 | VT_KEY, | 29 | VT_KEY, |
30 | VT_METATABLE | 30 | VT_METATABLE |
31 | }; | 31 | }; |
32 | bool_t inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_); | 32 | bool inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_); |
33 | 33 | ||
34 | // ################################################################################################ | 34 | // ################################################################################################ |
35 | 35 | ||
diff --git a/src/universe.h b/src/universe.h index 0224e99..77b3ea5 100644 --- a/src/universe.h +++ b/src/universe.h | |||
@@ -52,9 +52,9 @@ typedef struct ProtectedAllocator_s ProtectedAllocator; | |||
52 | struct s_Universe | 52 | struct s_Universe |
53 | { | 53 | { |
54 | // for verbose errors | 54 | // for verbose errors |
55 | bool_t verboseErrors; | 55 | bool verboseErrors; |
56 | 56 | ||
57 | bool_t demoteFullUserdata; | 57 | bool demoteFullUserdata; |
58 | 58 | ||
59 | // before a state is created, this function will be called to obtain the allocator | 59 | // before a state is created, this function will be called to obtain the allocator |
60 | lua_CFunction provide_allocator; | 60 | lua_CFunction provide_allocator; |