From 12afca7c245a7003c7d9e8e4445426794346940e Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Mon, 21 Feb 2022 20:09:51 +0800
Subject: [PATCH 67/76] uadk: comp: optimize for spin lock

Printf should be outside of the lock region.

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

diff --git a/wd_comp.c b/wd_comp.c
index 7868551..4a97f06 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -718,15 +718,21 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
 
 	ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg, priv);
 	if (ret < 0) {
+		pthread_spin_unlock(&ctx->lock);
 		WD_ERR("wd comp send err(%d)!\n", ret);
-		wd_put_msg_to_pool(&wd_comp_setting.pool, idx, msg->tag);
+		goto fail_with_msg;
 	}
 
 	pthread_spin_unlock(&ctx->lock);
 
 	ret = wd_add_task_to_async_queue(&wd_comp_env_config, idx);
 	if (ret)
-		wd_put_msg_to_pool(&wd_comp_setting.pool, idx, msg->tag);
+		goto fail_with_msg;
+
+	return 0;
+
+fail_with_msg:
+	wd_put_msg_to_pool(&wd_comp_setting.pool, idx, msg->tag);
 
 	return ret;
 }
-- 
2.25.1

