From 5875fe44ba7a240dd101f954c7dc83337a0c2cef Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 16 Jun 2021 18:41:14 +0200 Subject: changed lanes.threads() output so that several lanes with the same name don't clobber each other in the result table In the original implementations, the debug name was used as key, which meant that several lanes using the same name would cause only the oldest non-collected one to be listed in the results. Now the result is an array of tuples. --- src/lanes.c | 45 +++++++++++++++++++++++++-------------------- src/lanes.h | 2 +- 2 files changed, 26 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/lanes.c b/src/lanes.c index 8f159a9..f3fdc76 100644 --- a/src/lanes.c +++ b/src/lanes.c @@ -1652,26 +1652,31 @@ LUAG_FUNC( thread_index) // Return a list of all known lanes LUAG_FUNC( threads) { - int const top = lua_gettop( L); - Universe* U = universe_get( L); - - // List _all_ still running threads - // - MUTEX_LOCK( &U->tracking_cs); - if( U->tracking_first && U->tracking_first != TRACKING_END) - { - Lane* s = U->tracking_first; - lua_newtable( L); // {} - while( s != TRACKING_END) - { - lua_pushstring( L, s->debug_name); // {} "name" - push_thread_status( L, s); // {} "name" "status" - lua_rawset( L, -3); // {} - s = s->tracking_next; - } - } - MUTEX_UNLOCK( &U->tracking_cs); - return lua_gettop( L) - top; + int const top = lua_gettop( L); + Universe* U = universe_get( L); + + // List _all_ still running threads + // + MUTEX_LOCK( &U->tracking_cs); + if( U->tracking_first && U->tracking_first != TRACKING_END) + { + Lane* s = U->tracking_first; + int index = 0; + lua_newtable( L); // {} + while( s != TRACKING_END) + { + // insert a { name, status } tuple, so that several lanes with the same name can't clobber each other + lua_newtable( L); // {} {} + lua_pushstring( L, s->debug_name); // {} {} "name" + lua_setfield( L, -2, "name"); // {} {} + push_thread_status( L, s); // {} {} "status" + lua_setfield( L, -2, "status"); // {} {} + lua_rawseti( L, -2, ++ index); // {} + s = s->tracking_next; + } + } + MUTEX_UNLOCK( &U->tracking_cs); + return lua_gettop( L) - top; // 0 or 1 } #endif // HAVE_LANE_TRACKING diff --git a/src/lanes.h b/src/lanes.h index da0dd26..1a38ba5 100644 --- a/src/lanes.h +++ b/src/lanes.h @@ -11,7 +11,7 @@ #endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) #define LANES_VERSION_MAJOR 3 -#define LANES_VERSION_MINOR 14 +#define LANES_VERSION_MINOR 15 #define LANES_VERSION_PATCH 0 #define LANES_MIN_VERSION_REQUIRED(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>=PATCH)))) -- cgit v1.2.3-55-g6feb