Commit 2b8c23c7 authored by Daniel Verkamp's avatar Daniel Verkamp Committed by Jim Harris
Browse files

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: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/399930


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent ff3d53f7
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -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;