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++;