1
This commit is contained in:
parent
b17543dae9
commit
feaf1958a8
25
a8/xtimer.cc
25
a8/xtimer.cc
@ -123,6 +123,11 @@ static inline void InitTimerList(xtvec_base* base, xtimer_list* timer, int timer
|
|||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
|
|
||||||
|
struct XTimerPtr
|
||||||
|
{
|
||||||
|
xtimer_list* timer = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
XTimer::XTimer()
|
XTimer::XTimer()
|
||||||
{
|
{
|
||||||
base_ = new xtvec_base();
|
base_ = new xtvec_base();
|
||||||
@ -443,4 +448,24 @@ namespace a8
|
|||||||
delete node;
|
delete node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::weak_ptr<XTimerPtr> XTimer::GetTimerPtr(xtimer_list* timer)
|
||||||
|
{
|
||||||
|
std::shared_ptr<XTimerPtr> timer_ptr = std::make_shared<XTimerPtr>();
|
||||||
|
timer_ptr->timer = timer;
|
||||||
|
AddTimerDestoryHandle
|
||||||
|
(timer,
|
||||||
|
[timer_ptr] (xtimer_list* timer)
|
||||||
|
{
|
||||||
|
timer_ptr->timer = nullptr;
|
||||||
|
});
|
||||||
|
return timer_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void XTimer::DeleteTimer(std::weak_ptr<XTimerPtr>& ptr)
|
||||||
|
{
|
||||||
|
if (!ptr.expired()) {
|
||||||
|
DeleteTimer(ptr.lock()->timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ namespace a8
|
|||||||
typedef void (*XTimerAfterFunc)(const a8::XParams& param);
|
typedef void (*XTimerAfterFunc)(const a8::XParams& param);
|
||||||
typedef long long (*XGetTickCountFunc)(void*);
|
typedef long long (*XGetTickCountFunc)(void*);
|
||||||
typedef struct list_head XTimerDestoryHandle;
|
typedef struct list_head XTimerDestoryHandle;
|
||||||
|
struct XTimerPtr;
|
||||||
|
|
||||||
class XTimer
|
class XTimer
|
||||||
{
|
{
|
||||||
@ -53,6 +54,10 @@ namespace a8
|
|||||||
std::function<void(xtimer_list*)> cb);
|
std::function<void(xtimer_list*)> cb);
|
||||||
//移除定时器销毁事件
|
//移除定时器销毁事件
|
||||||
void RemoveTimerDestoryHandle(XTimerDestoryHandle* handle);
|
void RemoveTimerDestoryHandle(XTimerDestoryHandle* handle);
|
||||||
|
//获取定时器弱引用
|
||||||
|
std::weak_ptr<XTimerPtr> GetTimerPtr(xtimer_list* timer);
|
||||||
|
//删除弱引用指向的定时器
|
||||||
|
void DeleteTimer(std::weak_ptr<XTimerPtr>& ptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateTimer();
|
void UpdateTimer();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user