From 0b516e9490b51bdd15c347fcda35b5dbb06b4829 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 20 Mar 2024 09:09:27 +0100 Subject: C++ migration: bool_t → bool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cancel.cpp | 10 +++--- src/cancel.h | 2 +- src/deep.cpp | 9 +++--- src/keeper.cpp | 2 +- src/lanes.cpp | 59 +++++++++++++++++------------------- src/lanes_private.h | 2 +- src/linda.cpp | 31 +++++++++---------- src/macros_and_utils.h | 6 ++-- src/state.cpp | 4 +-- src/threading.cpp | 48 ++++++++++++++--------------- src/threading.h | 14 +++------ src/tools.cpp | 82 +++++++++++++++++++++++++------------------------- src/tools.h | 2 +- src/universe.h | 4 +-- 14 files changed, 131 insertions(+), 144 deletions(-) (limited to 'src') 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. * Called by cancellation hooks and/or pending Linda operations (because then * the check won't affect performance). * -* Returns TRUE if any locks are to be exited, and 'cancel_error()' called, +* Returns CANCEL_SOFT/HARD if any locks are to be exited, and 'cancel_error()' called, * to make execution of the lane end. */ 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) // ################################################################################################ -static cancel_result thread_cancel_soft( Lane* s, double secs_, bool_t wake_lindas_) +static cancel_result thread_cancel_soft( Lane* s, double secs_, bool wake_lindas_) { s->cancel_request = CANCEL_SOFT; // it's now signaled to stop // 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 // ################################################################################################ -static cancel_result thread_cancel_hard( lua_State* L, Lane* s, double secs_, bool_t force_, double waitkill_timeout_) +static cancel_result thread_cancel_hard( lua_State* L, Lane* s, double secs_, bool force_, double waitkill_timeout_) { cancel_result result; @@ -175,7 +175,7 @@ static cancel_result thread_cancel_hard( lua_State* L, Lane* s, double secs_, bo // ################################################################################################ -cancel_result thread_cancel( lua_State* L, Lane* s, CancelOp op_, double secs_, bool_t force_, double waitkill_timeout_) +cancel_result thread_cancel( lua_State* L, Lane* s, CancelOp op_, double secs_, bool force_, double waitkill_timeout_) { // remember that lanes are not transferable: only one thread can cancel a lane, so no multithreading issue here // 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) } { - bool_t force = lua_toboolean( L, 2); // FALSE if nothing there + bool const force = lua_toboolean( L, 2) ? true : false; // false if nothing there double forcekill_timeout = luaL_optnumber( L, 3, 0.0); 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 // crc64/we of string "CANCEL_TEST_KEY" generated at http://www.nitrxgen.net/hashgen/ static DECLARE_CONST_UNIQUE_KEY(CANCEL_TEST_KEY, 0xe66f5960c57d133a); // used as registry key -cancel_result thread_cancel( lua_State* L, Lane* s, CancelOp op_, double secs_, bool_t force_, double waitkill_timeout_); +cancel_result thread_cancel( lua_State* L, Lane* s, CancelOp op_, double secs_, bool force_, double waitkill_timeout_); static inline int cancel_error( lua_State* L) { 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 lua_getfield( L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); // DPC proxy metatable require() "module" _R._LOADED if( lua_istable( L, -1)) { - bool_t alreadyloaded; lua_pushvalue( L, -2); // DPC proxy metatable require() "module" _R._LOADED "module" lua_rawget( L, -2); // DPC proxy metatable require() "module" _R._LOADED module - alreadyloaded = lua_toboolean( L, -1); + int const alreadyloaded = lua_toboolean( L, -1); if( !alreadyloaded) // not loaded { int require_result; @@ -450,7 +449,7 @@ void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index) * the id function of the copied value, or NULL for non-deep userdata * (not copied) */ -bool_t copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) +bool copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) { char const* errmsg; 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 if( idfunc == NULL) { - return FALSE; // not a deep userdata + return false; // not a deep userdata } 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 lua_State* errL = (mode_ == eLM_FromKeeper) ? L2 : L; luaL_error( errL, errmsg); } - return TRUE; + return true; } \ 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) //out: true or nil int keepercall_set( lua_State* L) { - bool_t should_wake_writers = FALSE; + bool should_wake_writers{ false }; STACK_GROW( L, 6); // 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; /* * Push a table stored in registry onto Lua stack. * -* If there is no existing table, create one if 'create' is TRUE. +* If there is no existing table, create one if 'create' is true. * -* Returns: TRUE if a table was pushed -* FALSE if no table found, not created, and nothing pushed +* Returns: true if a table was pushed +* false if no table found, not created, and nothing pushed */ -static bool_t push_registry_table( lua_State* L, UniqueKey key, bool_t create) +static bool push_registry_table( lua_State* L, UniqueKey key, bool create) { STACK_GROW( L, 3); STACK_CHECK( L, 0); @@ -164,14 +164,14 @@ static bool_t push_registry_table( lua_State* L, UniqueKey key, bool_t create) if( !create) { - return FALSE; + return false; } lua_newtable( L); // t REGISTRY_SET( L, key, lua_pushvalue( L, -2)); } STACK_END( L, 1); - return TRUE; // table pushed + return true; // table pushed } #if HAVE_LANE_TRACKING() @@ -200,9 +200,9 @@ static void tracking_add( Lane* s) /* * A free-running lane has ended; remove it from tracking chain */ -static bool_t tracking_remove( Lane* s) +static bool tracking_remove( Lane* s) { - bool_t found = FALSE; + bool found{ false }; MUTEX_LOCK( &s->U->tracking_cs); { // Make sure (within the MUTEX) that we actually are in the chain @@ -219,7 +219,7 @@ static bool_t tracking_remove( Lane* s) { *ref = s->tracking_next; s->tracking_next = nullptr; - found = TRUE; + found = true; break; } ref = (Lane**) &((*ref)->tracking_next); @@ -278,7 +278,7 @@ LUAG_FUNC( set_finalizer) luaL_argcheck( L, lua_isfunction( L, 1), 1, "finalizer should be a function"); luaL_argcheck( L, lua_gettop( L) == 1, 1, "too many arguments"); // Get the current finalizer table (if any) - push_registry_table( L, FINALIZER_REGKEY, TRUE /*do create if none*/); // finalizer {finalisers} + push_registry_table( L, FINALIZER_REGKEY, true /*do create if none*/); // finalizer {finalisers} STACK_GROW( L, 2); lua_pushinteger( L, lua_rawlen( L, -1) + 1); // finalizer {finalisers} idx lua_pushvalue( L, 1); // finalizer {finalisers} idx finalizer @@ -309,7 +309,7 @@ static int run_finalizers( lua_State* L, int lua_rc) int n; int err_handler_index = 0; int rc = LUA_OK; // ... - if( !push_registry_table( L, FINALIZER_REGKEY, FALSE)) // ... finalizers? + if( !push_registry_table( L, FINALIZER_REGKEY, false)) // ... finalizers? { return 0; // no finalizers } @@ -406,9 +406,9 @@ static void selfdestruct_add( Lane* s) /* * A free-running lane has ended; remove it from selfdestruct chain */ -static bool_t selfdestruct_remove( Lane* s) +static bool selfdestruct_remove( Lane* s) { - bool_t found = FALSE; + bool found{ false }; MUTEX_LOCK( &s->U->selfdestruct_cs); { // Make sure (within the MUTEX) that we actually are in the chain @@ -427,7 +427,7 @@ static bool_t selfdestruct_remove( Lane* s) s->selfdestruct_next = nullptr; // the terminal shutdown should wait until the lane is done with its lua_close() ++ s->U->selfdestructing_count; - found = TRUE; + found = true; break; } ref = (Lane**) &((*ref)->selfdestruct_next); @@ -456,9 +456,9 @@ static int selfdestruct_gc( lua_State* L) while( s != SELFDESTRUCT_END) { // attempt a regular unforced hard cancel with a small timeout - bool_t cancelled = THREAD_ISNULL( s->thread) || thread_cancel( L, s, CO_Hard, 0.0001, FALSE, 0.0); + bool const cancelled = THREAD_ISNULL( s->thread) || thread_cancel( L, s, CO_Hard, 0.0001, false, 0.0); // if we failed, and we know the thread is waiting on a linda - if( cancelled == FALSE && s->status == WAITING && s->waiting_on != nullptr) + if( cancelled == false && s->status == WAITING && s->waiting_on != nullptr) { // signal the linda to wake up the thread so that it can react to the cancel query // 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) LUAG_FUNC( set_error_reporting) { - bool_t equal; luaL_checktype( L, 1, LUA_TSTRING); lua_pushliteral( L, "extended"); - equal = lua_rawequal( L, -1, 1); + int equal = lua_rawequal( L, -1, 1); lua_pop( L, 1); if( equal) { @@ -678,7 +677,6 @@ static int lane_error( lua_State* L) { lua_Debug ar; int n; - bool_t extended; // error message (any type) STACK_CHECK_ABS( L, 1); // some_error @@ -692,7 +690,7 @@ static int lane_error( lua_State* L) STACK_GROW( L, 3); REGISTRY_GET( L, EXTENDED_STACKTRACE_REGKEY); // some_error basic|extended - extended = lua_toboolean( L, -1); + bool const extended{ lua_toboolean(L, -1) ? true : false}; lua_pop( L, 1); // some_error // 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) MUTEX_UNLOCK( &s->done_lock); #endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR } - THREAD_CLEANUP_POP( FALSE); + THREAD_CLEANUP_POP( false); return 0; // ignored } @@ -1047,7 +1045,7 @@ LUAG_FUNC( lane_new) Lane** ud; char const* libs_str = lua_tostring( L, 2); - bool_t const have_priority = !lua_isnoneornil( L, 3); + bool const have_priority{ !lua_isnoneornil(L, 3) }; int const priority = have_priority ? (int) lua_tointeger( L, 3) : THREAD_PRIO_DEFAULT; uint_t const globals_idx = lua_isnoneornil( L, 4) ? 0 : 4; uint_t const package_idx = lua_isnoneornil( L, 5) ? 0 : 5; @@ -1304,7 +1302,7 @@ LUAG_FUNC( lane_new) // LUAG_FUNC( thread_gc) { - bool_t have_gc_cb = FALSE; + bool have_gc_cb{ false }; Lane* s = lua_toLane( L, 1); // ud // if there a gc callback? @@ -1315,7 +1313,7 @@ LUAG_FUNC( thread_gc) { lua_remove( L, -2); // ud gc_cb|nil lua_pushstring( L, s->debug_name); // ud gc_cb name - have_gc_cb = TRUE; + have_gc_cb = true; } else { @@ -1427,7 +1425,7 @@ LUAG_FUNC( thread_join) double wait_secs = luaL_optnumber( L, 2, -1.0); lua_State* L2 = s->L; int ret; - bool_t done = THREAD_ISNULL( s->thread) || THREAD_WAIT( &s->thread, wait_secs, &s->done_signal, &s->done_lock, &s->status); + bool const done{ THREAD_ISNULL(s->thread) || THREAD_WAIT(&s->thread, wait_secs, &s->done_signal, &s->done_lock, &s->status) }; if( !done || !L2) { STACK_GROW( L, 2); @@ -1486,7 +1484,7 @@ LUAG_FUNC( thread_join) default: DEBUGSPEW_CODE( fprintf( stderr, "Status: %d\n", s->status)); - ASSERT_L( FALSE); + ASSERT_L( false); ret = 0; } lua_close( L2); @@ -1532,11 +1530,10 @@ LUAG_FUNC( thread_index) } { // check if we already fetched the values from the thread or not - bool_t fetched; lua_Integer key = lua_tointeger( L, KEY); lua_pushinteger( L, 0); lua_rawget( L, USR); - fetched = !lua_isnil( L, -1); + bool const fetched{ !lua_isnil(L, -1) }; lua_pop( L, 1); // back to our 2 args + uservalue on the stack if( !fetched) { @@ -1820,7 +1817,7 @@ static volatile long s_initCount = 0; LUAG_FUNC( configure) { Universe* U = universe_get( L); - bool_t const from_master_state = (U == nullptr); + bool const from_master_state{ U == nullptr }; char const* name = luaL_checkstring( L, lua_upvalueindex( 1)); _ASSERT_L( L, lua_type( L, 1) == LUA_TTABLE); @@ -1879,10 +1876,10 @@ LUAG_FUNC( configure) lua_setmetatable( L, -2); // settings universe lua_pop( L, 1); // settings lua_getfield( L, 1, "verbose_errors"); // settings verbose_errors - U->verboseErrors = lua_toboolean( L, -1); + U->verboseErrors = lua_toboolean( L, -1) ? true : false; lua_pop( L, 1); // settings lua_getfield( L, 1, "demote_full_userdata"); // settings demote_full_userdata - U->demoteFullUserdata = lua_toboolean( L, -1); + U->demoteFullUserdata = lua_toboolean( L, -1) ? true : false; lua_pop( L, 1); // settings #if HAVE_LANE_TRACKING() 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 volatile enum e_cancel_request cancel_request; // - // M: sets to FALSE, flags TRUE for cancel request + // M: sets to false, flags true for cancel request // S: reads to see if cancel is requested #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) LUAG_FUNC( linda_send) { struct s_Linda* linda = lua_toLinda( L, 1); - bool_t ret = FALSE; + bool ret{ false }; enum e_cancel_request cancel = CANCEL_NONE; int pushed; time_d timeout = -1.0; uint_t key_i = 2; // index of first key, if timeout not there - bool_t as_nil_sentinel; // if not NULL, send() will silently send a single nil if nothing is provided if( lua_type( L, 2) == LUA_TNUMBER) // we don't want to use lua_isnumber() because of autocoercion { @@ -138,7 +137,7 @@ LUAG_FUNC( linda_send) ++ key_i; } - as_nil_sentinel = equal_unique_key( L, key_i, NIL_SENTINEL); + 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 if( as_nil_sentinel) { // the real key to send data to is after the NIL_SENTINEL marker @@ -168,13 +167,12 @@ LUAG_FUNC( linda_send) keeper_toggle_nil_sentinels( L, key_i + 1, eLM_ToKeeper); { - bool_t try_again = TRUE; Lane* const s = get_lane_from_registry( L); Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); lua_State* KL = K ? K->L : nullptr; // need to do this for 'STACK_CHECK' if( KL == nullptr) return 0; STACK_CHECK( KL, 0); - for( ;;) + for(bool try_again{ true };;) { if( s != nullptr) { @@ -196,7 +194,7 @@ LUAG_FUNC( linda_send) } ASSERT_L( pushed == 1); - ret = lua_toboolean( L, -1); + ret = lua_toboolean( L, -1) ? true : false; lua_pop( L, 1); if( ret) @@ -328,11 +326,10 @@ LUAG_FUNC( linda_receive) } { - bool_t try_again = TRUE; Lane* const s = get_lane_from_registry( L); Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); if( K == nullptr) return 0; - for( ;;) + for (bool try_again{ true };;) { if( s != nullptr) { @@ -425,7 +422,7 @@ LUAG_FUNC( linda_set) { struct s_Linda* const linda = lua_toLinda( L, 1); int pushed; - bool_t has_value = lua_gettop( L) > 2; + bool const has_value{ lua_gettop(L) > 2 }; // make sure the key is of a valid type (throws an error if not the case) check_key_types( L, 2, 2); @@ -647,7 +644,7 @@ LUAG_FUNC( linda_deep) * Useful for concatenation or debugging purposes */ -static int linda_tostring( lua_State* L, int idx_, bool_t opt_) +static int linda_tostring( lua_State* L, int idx_, bool opt_) { struct s_Linda* linda = (struct s_Linda*) luaG_todeep( L, linda_id, idx_); if( !opt_) @@ -670,7 +667,7 @@ static int linda_tostring( lua_State* L, int idx_, bool_t opt_) LUAG_FUNC( linda_tostring) { - return linda_tostring( L, 1, FALSE); + return linda_tostring( L, 1, false); } @@ -683,16 +680,16 @@ LUAG_FUNC( linda_tostring) */ LUAG_FUNC( linda_concat) { // linda1? linda2? - bool_t atLeastOneLinda = FALSE; + bool atLeastOneLinda{ false }; // Lua semantics enforce that one of the 2 arguments is a Linda, but not necessarily both. - if( linda_tostring( L, 1, TRUE)) + if( linda_tostring( L, 1, true)) { - atLeastOneLinda = TRUE; + atLeastOneLinda = true; lua_replace( L, 1); } - if( linda_tostring( L, 2, TRUE)) + if( linda_tostring( L, 2, true)) { - atLeastOneLinda = TRUE; + atLeastOneLinda = true; lua_replace( L, 2); } if( !atLeastOneLinda) // should not be possible @@ -727,7 +724,7 @@ LUAG_FUNC( linda_towatch) if( pushed == 0) { // if the linda is empty, don't return nil - pushed = linda_tostring( L, 1, FALSE); + pushed = linda_tostring( L, 1, false); } return pushed; } 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; int const L##_delta = offset_; \ if( (L##_delta < 0) || (lua_gettop( L) < L##_delta)) \ { \ - assert( FALSE); \ + assert( false); \ (void) luaL_error( L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop( L), L##_delta, __FILE__, __LINE__); \ } \ int const L##_oldtop = lua_gettop( L) - L##_delta @@ -51,7 +51,7 @@ extern char const* debugspew_indent; int const L##_pos = offset_; \ if( lua_gettop( L) < L##_pos) \ { \ - assert( FALSE); \ + assert( false); \ (void) luaL_error( L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop( L), L##_pos, __FILE__, __LINE__); \ } \ int const L##_oldtop = 0 @@ -63,7 +63,7 @@ extern char const* debugspew_indent; int stack_check_b = (change); \ if( stack_check_a != stack_check_b) \ { \ - assert( FALSE); \ + assert( false); \ luaL_error( L, "STACK ASSERT failed (%d not %d): %s:%d", stack_check_a, stack_check_b, __FILE__, __LINE__); \ } \ } 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 name_ = libs[i].name; // note that the provided name_ doesn't necessarily ends with '\0', hence len_ if( libfunc != NULL) { - bool_t const isLanesCore = (libfunc == require_lanes_core) ? TRUE : FALSE; // don't want to create a global for "lanes.core" + bool const isLanesCore{ libfunc == require_lanes_core }; // don't want to create a global for "lanes.core" DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening %.*s library\n" INDENT_END, (int) len_, name_)); STACK_CHECK( L, 0); // open the library as if through require(), and create a global as well if necessary (the library table is left on the stack) luaL_requiref( L, name_, libfunc, !isLanesCore); // lanes.core doesn't declare a global, so scan it here and now - if( isLanesCore == TRUE) + if( isLanesCore == true) { populate_func_lookup_table( L, -1, name_); } 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. /* Linux needs to check, whether it's been run as root */ #ifdef PLATFORM_LINUX - volatile bool_t sudo; + volatile bool sudo; #endif #ifdef PLATFORM_OSX @@ -271,12 +271,12 @@ static void prepare_timeout( struct timespec *ts, time_d abs_secs ) { #if _WIN32_WINNT < 0x0600 // CONDITION_VARIABLE aren't available // void MUTEX_INIT( MUTEX_T *ref ) { - *ref= CreateMutex( NULL /*security attr*/, FALSE /*not locked*/, NULL ); + *ref= CreateMutex( nullptr /*security attr*/, false /*not locked*/, nullptr ); if (!ref) FAIL( "CreateMutex", GetLastError() ); } void MUTEX_FREE( MUTEX_T *ref ) { if (!CloseHandle(*ref)) FAIL( "CloseHandle (mutex)", GetLastError() ); - *ref= NULL; + *ref= nullptr; } void MUTEX_LOCK( MUTEX_T *ref ) { @@ -352,7 +352,7 @@ void THREAD_SET_AFFINITY( unsigned int aff) } } -bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) +bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs) { DWORD ms = (secs<0.0) ? INFINITE : (DWORD)((secs*1000.0)+0.5); @@ -363,10 +363,10 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) // WAIT_TIMEOUT // WAIT_FAILED more info via GetLastError() - if (rc == WAIT_TIMEOUT) return FALSE; + if (rc == WAIT_TIMEOUT) return false; if( rc !=0) FAIL( "WaitForSingleObject", rc==WAIT_FAILED ? GetLastError() : rc); *ref= NULL; // thread no longer usable - return TRUE; + return true; } // void THREAD_KILL( THREAD_T *ref ) @@ -420,9 +420,9 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) { InitializeCriticalSection( &ref->signalCS); InitializeCriticalSection( &ref->countCS); - if( 0 == (ref->waitEvent = CreateEvent( 0, TRUE, FALSE, 0))) // manual-reset + if( 0 == (ref->waitEvent = CreateEvent( 0, true, false, 0))) // manual-reset FAIL( "CreateEvent", GetLastError()); - if( 0 == (ref->waitDoneEvent = CreateEvent( 0, FALSE, FALSE, 0))) // auto-reset + if( 0 == (ref->waitDoneEvent = CreateEvent( 0, false, false, 0))) // auto-reset FAIL( "CreateEvent", GetLastError()); ref->waitersCount = 0; } @@ -435,7 +435,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) DeleteCriticalSection( &ref->signalCS); } - bool_t SIGNAL_WAIT( SIGNAL_T* ref, MUTEX_T* mu_ref, time_d abs_secs) + bool SIGNAL_WAIT( SIGNAL_T* ref, MUTEX_T* mu_ref, time_d abs_secs) { DWORD errc; DWORD ms; @@ -458,7 +458,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) LeaveCriticalSection( &ref->countCS); LeaveCriticalSection( &ref->signalCS); - errc = SignalObjectAndWait( *mu_ref, ref->waitEvent, ms, FALSE); + errc = SignalObjectAndWait( *mu_ref, ref->waitEvent, ms, false); EnterCriticalSection( &ref->countCS); if( 0 == -- ref->waitersCount) @@ -473,13 +473,13 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) switch( errc) { case WAIT_TIMEOUT: - return FALSE; + return false; case WAIT_OBJECT_0: - return TRUE; + return true; } FAIL( "SignalObjectAndWait", GetLastError()); - return FALSE; + return false; } void SIGNAL_ALL( SIGNAL_T* ref) @@ -521,7 +521,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) (void)ref; } - bool_t SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu_ref, time_d abs_secs) + bool SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu_ref, time_d abs_secs) { long ms; @@ -544,14 +544,14 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) { if( GetLastError() == ERROR_TIMEOUT) { - return FALSE; + return false; } else { FAIL( "SleepConditionVariableCS", GetLastError()); } } - return TRUE; + return true; } void SIGNAL_ONE( SIGNAL_T *ref ) @@ -620,7 +620,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) * a timed out sleep. A Linda with some other key read, or just because * PThread cond vars can wake up unwantedly. */ - bool_t SIGNAL_WAIT( SIGNAL_T *ref, pthread_mutex_t *mu, time_d abs_secs ) { + bool SIGNAL_WAIT( SIGNAL_T *ref, pthread_mutex_t *mu, time_d abs_secs ) { if (abs_secs<0.0) { PT_CALL( pthread_cond_wait( ref, mu ) ); // infinite } else { @@ -632,10 +632,10 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) rc= pthread_cond_timedwait( ref, mu, &ts ); - if (rc==ETIMEDOUT) return FALSE; + if (rc==ETIMEDOUT) return false; if (rc) { _PT_FAIL( rc, "pthread_cond_timedwait()", __FILE__, __LINE__ ); } } - return TRUE; + return true; } // void SIGNAL_ONE( SIGNAL_T *ref ) { @@ -778,7 +778,7 @@ static int select_prio(int prio /* -3..+3 */) void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (*func)( void*), void* data, int prio /* -3..+3 */) { pthread_attr_t a; - bool_t const change_priority = + bool const change_priority = #ifdef PLATFORM_LINUX sudo && // only root-privileged process can change priorities #endif @@ -935,13 +935,13 @@ void THREAD_SET_AFFINITY( unsigned int aff) * 'mu_ref' is a lock we should use for the waiting; initially unlocked. * Same lock as passed to THREAD_EXIT. * - * Returns TRUE for successful wait, FALSE for timed out + * Returns true for successful wait, false for timed out */ -bool_t THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu_ref, volatile enum e_status *st_ref) +bool THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu_ref, volatile enum e_status *st_ref) { struct timespec ts_store; const struct timespec *timeout= NULL; - bool_t done; + bool done; // Do timeout counting before the locks // @@ -960,7 +960,7 @@ bool_t THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T * */ if (!timeout) { PT_CALL( pthread_join( *ref, NULL /*ignore exit value*/ )); - done= TRUE; + done = true; } else { int rc= PTHREAD_TIMEDJOIN( *ref, NULL, timeout ); 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 @@ */ #include "platform.h" -typedef int bool_t; -#ifndef FALSE -# define FALSE 0 -# define TRUE 1 -#endif - typedef unsigned int uint_t; #include @@ -165,7 +159,7 @@ time_d now_secs(void); time_d SIGNAL_TIMEOUT_PREPARE( double rel_secs ); -bool_t SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu, time_d timeout ); +bool SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu, time_d timeout ); /*---=== Threading ===--- @@ -209,7 +203,7 @@ bool_t SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu, time_d timeout ); void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (*func)( void*), void* data, int prio /* -3..+3 */); # if defined(PLATFORM_LINUX) - extern volatile bool_t sudo; + extern volatile bool sudo; # ifdef LINUX_SCHED_RR # define THREAD_PRIO_MIN (sudo ? -3 : 0) # else @@ -245,10 +239,10 @@ bool_t SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu, time_d timeout ); #if THREADWAIT_METHOD == THREADWAIT_TIMEOUT -bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs); +bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs); #define THREAD_WAIT( a, b, c, d, e) THREAD_WAIT_IMPL( a, b) #else // THREADWAIT_METHOD == THREADWAIT_CONDVAR -bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs, SIGNAL_T *signal_ref, MUTEX_T *mu_ref, volatile enum e_status *st_ref); +bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs, SIGNAL_T *signal_ref, MUTEX_T *mu_ref, volatile enum e_status *st_ref); #define THREAD_WAIT THREAD_WAIT_IMPL #endif // // THREADWAIT_METHOD == THREADWAIT_CONDVAR 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. #include "uniquekey.h" // functions implemented in deep.c -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_); +extern bool copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_); extern void push_registry_subtable( lua_State* L, UniqueKey key_); 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 /* * Push a looked-up table, or nothing if we found nothing */ -static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) +static bool lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) { // get the name of the table we want to send size_t len; char const* fqn = find_lookup_name( L, i, mode_, upName_, &len); if( NULL == fqn) // name not found, it is some user-created table { - return FALSE; + return false; } // push the equivalent table in the destination's stack, retrieved from the lookup table 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 { default: // shouldn't happen, in theory... (void) luaL_error( L, "internal error: unknown lookup mode"); - return FALSE; + return false; case eLM_ToKeeper: // 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 { lua_pop( L2, 2); // STACK_MID( L2, 0); - return FALSE; + return false; } else if( !lua_istable( L2, -1)) { @@ -822,13 +822,13 @@ static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mo , fqn , to ? to : "main" ); - return FALSE; + return false; } lua_remove( L2, -2); // t break; } STACK_END( L2, 1); - return TRUE; + return true; } @@ -839,12 +839,12 @@ static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mo * * Always pushes a table to 'L2'. * - * Returns TRUE if the table was cached (no need to fill it!); FALSE if + * Returns true if the table was cached (no need to fill it!); false if * it's a virgin. */ -static bool_t push_cached_table( lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i) +static bool push_cached_table( lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i) { - bool_t not_found_in_cache; // L2 + bool not_found_in_cache; // L2 DECLARE_CONST_UNIQUE_KEY( p, lua_topointer( L, i)); 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, // We don't need to use the from state ('L') in ID since the life span // is only for the duration of a copy (both states are locked). // push a light userdata uniquely representing the table - push_unique_key( L2, p); // ... p + push_unique_key( L2, p); // ... p //fprintf( stderr, "<< ID: %s >>\n", lua_tostring( L2, -1)); - lua_rawget( L2, L2_cache_i); // ... {cached|nil} + lua_rawget( L2, L2_cache_i); // ... {cached|nil} not_found_in_cache = lua_isnil( L2, -1); if( not_found_in_cache) { @@ -1391,7 +1391,7 @@ static void copy_cached_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua } } -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_) +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_) { STACK_CHECK( L, 0); 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 lua_pop( L, 1); // ... STACK_END( L2, 1); STACK_MID( L, 0); - return TRUE; + return true; } STACK_END( L, 0); - return FALSE; + return false; } 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 */ static DECLARE_CONST_UNIQUE_KEY( CLONABLES_CACHE_KEY, 0xD04EE018B3DEE8F5); -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_) +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_) { void* const source = lua_touserdata( L, source_i_); 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 if ( !lua_isnil( L2, -1)) { STACK_MID( L2, 1); - return TRUE; + return true; } else { @@ -1536,7 +1536,7 @@ static bool_t copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_Stat if( !lua_getmetatable( L, source_i_)) // ... mt? { STACK_MID( L, 0); - return FALSE; + return false; } // no __lanesclone? -> not clonable @@ -1545,7 +1545,7 @@ static bool_t copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_Stat { lua_pop( L, 2); // ... STACK_MID( L, 0); - return FALSE; + return false; } // 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 STACK_END( L2, 1); lua_pop( L, 1); // ... STACK_END( L, 0); - return TRUE; + return true; } -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_) +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_) { STACK_CHECK( L, 0); STACK_CHECK( L2, 0); if( vt == VT_KEY) { - return FALSE; + return false; } // try clonable userdata first @@ -1637,7 +1637,7 @@ static bool_t inter_copy_userdata( Universe* U, lua_State* L2, uint_t L2_cache_i { STACK_MID( L, 0); STACK_MID( L2, 1); - return TRUE; + return true; } STACK_MID( L, 0); @@ -1649,7 +1649,7 @@ static bool_t inter_copy_userdata( Universe* U, lua_State* L2, uint_t L2_cache_i { STACK_MID( L, 0); STACK_MID( L2, 1); - return TRUE; + return true; } STACK_MID( L, 0); @@ -1668,14 +1668,14 @@ static bool_t inter_copy_userdata( Universe* U, lua_State* L2, uint_t L2_cache_i STACK_END( L2, 1); STACK_END( L, 0); - return TRUE; + return true; } -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_) +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_) { if( vt == VT_KEY) { - return FALSE; + return false; } 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 lua_pop( L, 1); // ... STACK_MID( L, 0); STACK_MID( L2, 1); - return TRUE; + return true; } lua_pop( L2, 1); // ... @@ -1761,14 +1761,14 @@ static bool_t inter_copy_function( Universe* U, lua_State* L2, uint_t L2_cache_i } STACK_END( L2, 1); STACK_END( L, 0); - return TRUE; + return true; } -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_) +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_) { if( vt == VT_KEY) { - return FALSE; + return false; } 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 if( lookup_table( L2, L, i, mode_, upName_)) { 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 - return TRUE; + return true; } /* 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 if( push_cached_table( L2, L2_cache_i, L, i)) { ASSERT_L( lua_istable( L2, -1)); // from cache - return TRUE; + return true; } ASSERT_L( lua_istable( L2, -1)); @@ -1821,7 +1821,7 @@ static bool_t inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, l } STACK_END( L2, 1); STACK_END( L, 0); - return TRUE; + return true; } /* @@ -1832,11 +1832,11 @@ static bool_t inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, l * * 'i' is an absolute index (no -1, ...) * -* Returns TRUE if value was pushed, FALSE if its type is non-supported. +* Returns true if value was pushed, false if its type is non-supported. */ -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_) +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_) { - bool_t ret = TRUE; + bool ret{ true }; int val_type = lua_type( L, i); static int const pod_mask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); 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* case LUA_TBOOLEAN: { - bool_t v = lua_toboolean( L, i); + int const v{ lua_toboolean(L, i) }; DEBUGSPEW_CODE( fprintf( stderr, "%s\n", v ? "true" : "false")); lua_pushboolean( L2, v); } @@ -1921,7 +1921,7 @@ bool_t inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* case LUA_TNIL: if( vt == VT_KEY) { - ret = FALSE; + ret = false; break; } lua_pushnil( L2); @@ -1939,7 +1939,7 @@ bool_t inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* case 10: // LuaJIT CDATA case LUA_TTHREAD: - ret = FALSE; + ret = false; break; } @@ -1964,7 +1964,7 @@ int luaG_inter_copy( Universe* U, lua_State* L, lua_State* L2, uint_t n, LookupM uint_t i, j; char tmpBuf[16]; char const* pBuf = U->verboseErrors ? tmpBuf : "?"; - bool_t copyok = TRUE; + bool copyok{ true }; DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_inter_copy()\n" INDENT_END)); 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 VT_KEY, VT_METATABLE }; -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_); +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_); // ################################################################################################ 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; struct s_Universe { // for verbose errors - bool_t verboseErrors; + bool verboseErrors; - bool_t demoteFullUserdata; + bool demoteFullUserdata; // before a state is created, this function will be called to obtain the allocator lua_CFunction provide_allocator; -- cgit v1.2.3-55-g6feb