[v1,3/7] eal_memzone: bail out on initialized
Checks
Commit Message
From: Sinan Kaya <okaya@kernel.org>
Initialize memzone once and bail out if someone calls init
multiple times.
Signed-off-by: Sinan Kaya <okaya@kernel.org>
---
lib/eal/common/eal_common_memzone.c | 6 ++++++
1 file changed, 6 insertions(+)
Comments
On Mon, 14 Aug 2023 21:38:22 -0400
okaya@kernel.org wrote:
> + static int initialized = 0;
> int ret = 0;
>
> + if (initialized)
> + return 0;
> +
> /* get pointer to global configuration */
> mcfg = rte_eal_get_configuration()->mem_config;
>
> @@ -415,6 +419,8 @@ rte_eal_memzone_init(void)
>
> rte_rwlock_write_unlock(&mcfg->mlock);
>
> + initialized = 1;
> +
> return ret;
> }
Use a bool for this.
@@ -395,8 +395,12 @@ int
rte_eal_memzone_init(void)
{
struct rte_mem_config *mcfg;
+ static int initialized = 0;
int ret = 0;
+ if (initialized)
+ return 0;
+
/* get pointer to global configuration */
mcfg = rte_eal_get_configuration()->mem_config;
@@ -415,6 +419,8 @@ rte_eal_memzone_init(void)
rte_rwlock_write_unlock(&mcfg->mlock);
+ initialized = 1;
+
return ret;
}