From: Wenkai Lin linwenkai6@hisilicon.com
1. Separate rx_cnt auto-increment and judgment. 2. Reduce the condition judgment in the case of eagain.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd_util.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/wd_util.c b/wd_util.c index 2635dc3..0744ff0 100644 --- a/wd_util.c +++ b/wd_util.c @@ -1822,24 +1822,28 @@ int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_hand do { if (epoll_en) { ret = wd_ctx_wait(ctx, POLL_TIME); - if (ret < 0) + if (unlikely(ret < 0)) WD_ERR("wd ctx wait timeout(%d)!\n", ret); }
ret = msg_handle->recv(drv, ctx, msg); - if (ret == -WD_EAGAIN) { - if (unlikely(rx_cnt++ >= timeout)) { - WD_ERR("failed to recv msg: timeout!\n"); - return -WD_ETIMEDOUT; + if (ret != -WD_EAGAIN) { + if (unlikely(ret < 0)) { + WD_ERR("failed to recv msg: error = %d!\n", ret); + return ret; } + break; + }
- if (balance && *balance > WD_BALANCE_THRHD) - usleep(1); - } else if (unlikely(ret < 0)) { - WD_ERR("failed to recv msg: error = %d!\n", ret); - return ret; + rx_cnt++; + if (unlikely(rx_cnt >= timeout)) { + WD_ERR("failed to recv msg: timeout!\n"); + return -WD_ETIMEDOUT; } - } while (ret < 0); + + if (balance && *balance > WD_BALANCE_THRHD) + usleep(1); + } while (1);
if (balance) *balance = rx_cnt;