From 2b8c23c7b8f956c62682a3f72e933a370d95eb00 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 14 Feb 2018 11:17:08 -0700 Subject: [PATCH] env: make spdk_env_get_last_core() thread safe Previously, the maximum core value was cached in a static variable, but this isn't safe if multiple threads are calling at the same time. Iterating over all core numbers is not very expensive, so just recalculate the value for every call. Change-Id: I4fab072f4a96ecc8801e1db293b3921a6f1534f9 Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/399930 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris --- lib/env_dpdk/threads.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/env_dpdk/threads.c b/lib/env_dpdk/threads.c index 1e23906cd..84298ae3a 100644 --- a/lib/env_dpdk/threads.c +++ b/lib/env_dpdk/threads.c @@ -58,12 +58,7 @@ uint32_t spdk_env_get_last_core(void) { uint32_t i; - static uint32_t last_core = UINT32_MAX; - - /* Already know the last_core, just return */ - if (last_core != UINT32_MAX) { - return last_core; - } + uint32_t last_core = UINT32_MAX; SPDK_ENV_FOREACH_CORE(i) { last_core = i;