From 00d8dd57f97586658770a258f3e8fb331180f457 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Thu, 10 Mar 2022 20:03:15 +0800
Subject: [PATCH 091/109] uadk: mempool: fix redundant assignment

1. pos_first is no need to be assinged because it
will get a value later.
2. improve  performance by giving other threads or
processes a chance to run

Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
 wd_mempool.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/wd_mempool.c b/wd_mempool.c
index bfacd28..8467c48 100644
--- a/wd_mempool.c
+++ b/wd_mempool.c
@@ -14,6 +14,7 @@
 #include <sys/mman.h>
 #include <sys/param.h>
 #include <sys/queue.h>
+#include <pthread.h>
 #include "wd.h"
 
 #define SYSFS_NODE_PATH			"/sys/devices/system/node/node"
@@ -409,8 +410,8 @@ static int alloc_block_from_mempool(struct mempool *mp,
 					int mem_combined_num,
 					int mem_splited_num)
 {
-	int pos_first = pos;
 	int pos_last = pos;
+	int pos_first;
 	int i, ret;
 
 	do {
@@ -607,7 +608,9 @@ void wd_blockpool_destroy(handle_t blkpool)
 
 	mp = bp->mp;
 	wd_atomic_sub(&bp->ref, 1);
-	while(wd_atomic_load(&bp->ref));
+	while (wd_atomic_load(&bp->ref))
+		sched_yield();
+
 	free_mem_to_mempool(bp);
 	free(bp->blk_elem);
 	free(bp);
-- 
2.27.0

