[mpp_list]: Add wait function

NOTE: The wait function MUST be used with lock protection.

Change-Id: I14f48795d5833c9aedc311c56139775bf07f0e79
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
Herman Chen
2022-04-01 14:58:12 +08:00
parent 7a5544b8ec
commit 275705e088
2 changed files with 37 additions and 0 deletions

View File

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

View File

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