From 216a7c3d0b391135ecb9752ba2c62f3d185b05d7 Mon Sep 17 00:00:00 2001 From: Krzysztof Karas Date: Tue, 25 Jan 2022 09:21:27 +0000 Subject: [PATCH] spdk_top: add a helper function to check if thread exists This check is going to be called in two places in the next patch. The purpose is to eliminate duplicating code. Change-Id: I1d739395453c083479c104e2774b1e0c01962bd1 Signed-off-by: Krzysztof Karas Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11234 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- app/spdk_top/spdk_top.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/spdk_top/spdk_top.c b/app/spdk_top/spdk_top.c index e47bdb73a..70ed75485 100644 --- a/app/spdk_top/spdk_top.c +++ b/app/spdk_top/spdk_top.c @@ -2327,30 +2327,36 @@ draw_thread_win_content(WINDOW *thread_win, struct rpc_thread_info *thread_info) wrefresh(thread_win); } +static int +get_single_thread_info(uint64_t thread_id, struct rpc_thread_info *thread_info) +{ + uint64_t i; + + for (i = 0; i < g_last_threads_count; i++) { + if (g_threads_info[i].id == thread_id) { + memcpy(thread_info, &g_threads_info[i], sizeof(struct rpc_thread_info)); + return 0; + } + } + + print_bottom_message("Selected thread no longer exists. Exiting pop-up."); + return -1; +} + static void display_thread(uint64_t thread_id, uint8_t current_page) { PANEL *thread_panel; WINDOW *thread_win; struct rpc_thread_info thread_info; - uint64_t pollers_count, i; + uint64_t pollers_count; int c; bool stop_loop = false; memset(&thread_info, 0, sizeof(thread_info)); pthread_mutex_lock(&g_thread_lock); - /* Use local copy of thread_info */ - for (i = 0; i < g_last_threads_count; i++) { - if (g_threads_info[i].id == thread_id) { - memcpy(&thread_info, &g_threads_info[i], sizeof(struct rpc_thread_info)); - break; - } - } - - /* We did not find this thread, so we cannot show its information. */ - if (i == g_last_threads_count) { - print_bottom_message("This thread does not exist."); + if (get_single_thread_info(thread_id, &thread_info)) { pthread_mutex_unlock(&g_thread_lock); return; }