aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2021-06-16 18:41:14 +0200
committerBenoit Germain <bnt.germain@gmail.com>2021-06-16 18:41:14 +0200
commit5875fe44ba7a240dd101f954c7dc83337a0c2cef (patch)
tree5c53b56b750c135163d462a39217fb88f8741ed6 /src
parent21b2ac762ff8a5926872963aa2fd8feeb1bf3b39 (diff)
downloadlanes-5875fe44ba7a240dd101f954c7dc83337a0c2cef.tar.gz
lanes-5875fe44ba7a240dd101f954c7dc83337a0c2cef.tar.bz2
lanes-5875fe44ba7a240dd101f954c7dc83337a0c2cef.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/lanes.c45
-rw-r--r--src/lanes.h2
2 files changed, 26 insertions, 21 deletions
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)
1652// Return a list of all known lanes 1652// Return a list of all known lanes
1653LUAG_FUNC( threads) 1653LUAG_FUNC( threads)
1654{ 1654{
1655 int const top = lua_gettop( L); 1655 int const top = lua_gettop( L);
1656 Universe* U = universe_get( L); 1656 Universe* U = universe_get( L);
1657 1657
1658 // List _all_ still running threads 1658 // List _all_ still running threads
1659 // 1659 //
1660 MUTEX_LOCK( &U->tracking_cs); 1660 MUTEX_LOCK( &U->tracking_cs);
1661 if( U->tracking_first && U->tracking_first != TRACKING_END) 1661 if( U->tracking_first && U->tracking_first != TRACKING_END)
1662 { 1662 {
1663 Lane* s = U->tracking_first; 1663 Lane* s = U->tracking_first;
1664 lua_newtable( L); // {} 1664 int index = 0;
1665 while( s != TRACKING_END) 1665 lua_newtable( L); // {}
1666 { 1666 while( s != TRACKING_END)
1667 lua_pushstring( L, s->debug_name); // {} "name" 1667 {
1668 push_thread_status( L, s); // {} "name" "status" 1668 // insert a { name, status } tuple, so that several lanes with the same name can't clobber each other
1669 lua_rawset( L, -3); // {} 1669 lua_newtable( L); // {} {}
1670 s = s->tracking_next; 1670 lua_pushstring( L, s->debug_name); // {} {} "name"
1671 } 1671 lua_setfield( L, -2, "name"); // {} {}
1672 } 1672 push_thread_status( L, s); // {} {} "status"
1673 MUTEX_UNLOCK( &U->tracking_cs); 1673 lua_setfield( L, -2, "status"); // {} {}
1674 return lua_gettop( L) - top; 1674 lua_rawseti( L, -2, ++ index); // {}
1675 s = s->tracking_next;
1676 }
1677 }
1678 MUTEX_UNLOCK( &U->tracking_cs);
1679 return lua_gettop( L) - top; // 0 or 1
1675} 1680}
1676#endif // HAVE_LANE_TRACKING 1681#endif // HAVE_LANE_TRACKING
1677 1682
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 @@
11#endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) 11#endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC)
12 12
13#define LANES_VERSION_MAJOR 3 13#define LANES_VERSION_MAJOR 3
14#define LANES_VERSION_MINOR 14 14#define LANES_VERSION_MINOR 15
15#define LANES_VERSION_PATCH 0 15#define LANES_VERSION_PATCH 0
16 16
17#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)))) 17#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))))