mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-21 16:19:23 +08:00
[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:
@@ -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;
|
||||
|
@@ -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++;
|
||||
|
Reference in New Issue
Block a user