From 275705e088e5b49a69a514cb75269fe4e973405f Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Fri, 1 Apr 2022 14:58:12 +0800 Subject: [PATCH] [mpp_list]: Add wait function NOTE: The wait function MUST be used with lock protection. Change-Id: I14f48795d5833c9aedc311c56139775bf07f0e79 Signed-off-by: Herman Chen --- osal/inc/mpp_list.h | 5 +++++ osal/mpp_list.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/osal/inc/mpp_list.h b/osal/inc/mpp_list.h index 6e5fbd77..ba34349b 100644 --- a/osal/inc/mpp_list.h +++ b/osal/inc/mpp_list.h @@ -18,6 +18,7 @@ #define __MPP_LIST_H__ #include "rk_type.h" +#include "mpp_err.h" #include "mpp_thread.h" @@ -64,6 +65,10 @@ public: RK_S32 flush(); + // for list wait + MPP_RET wait_lt(RK_S64 timeout, RK_S32 val); + MPP_RET wait_gt(RK_S64 timeout, RK_S32 val); + private: node_destructor destroy; struct mpp_list_node *head; diff --git a/osal/mpp_list.cpp b/osal/mpp_list.cpp index 3f8eab5e..a747c63c 100644 --- a/osal/mpp_list.cpp +++ b/osal/mpp_list.cpp @@ -299,6 +299,38 @@ RK_S32 mpp_list::flush() return 0; } +MPP_RET mpp_list::wait_lt(RK_S64 timeout, RK_S32 val) +{ + if (list_size() <= val) + return MPP_OK; + + if (!timeout) + return MPP_NOK; + + if (timeout < 0) + wait(); + else + wait(timeout); + + return list_size() <= val ? MPP_OK : MPP_NOK; +} + +MPP_RET mpp_list::wait_gt(RK_S64 timeout, RK_S32 val) +{ + if (list_size() >= val) + return MPP_OK; + + if (!timeout) + return MPP_NOK; + + if (timeout < 0) + wait(); + else + wait(timeout); + + return list_size() >= val ? MPP_OK : MPP_NOK; +} + RK_U32 mpp_list::get_key() { return keys++;