Skip to content

Commit

Permalink
修复HCPPTimer的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
HEYAHONG committed Jun 13, 2024
1 parent b5a9b02 commit 730e409
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hcppbox/HCPPTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void HCPPTimer::timeout()
bool HCPPTimer::SetParent(HCPPObject * parent,bool force_update)
{
//定时器必须要求顶层父对象为线程
if(parent==NULL || parent->GetTopHCPPObject()->GetType() == HCPPOBJECT_TYPE_THREAD)
if(parent==NULL || parent->GetTopHCPPObject()->GetType() != HCPPOBJECT_TYPE_THREAD)
{
parent=HCPPTimerGlobal::g_timerthread.GetThread();
}
Expand Down
12 changes: 11 additions & 1 deletion test/HCPPObjectTest/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@
void Timer_main()
{
printf(__FILE__ " Start\r\n");

printf("-----Test 1-----\r\n");
HCPPThread *threadhandle=HCPPThread::New();
new HCPPTimer(threadhandle,std::chrono::seconds(1),[](HCPPTimer *timer)
{
static int cnt=0;
printf("Period Timer %08X:cnt=%d\r\n",(uint32_t)reinterpret_cast<uintptr_t>(timer),cnt++);
},false);
std::this_thread::sleep_for(std::chrono::seconds(5));
threadhandle->DeleteThread();
std::this_thread::sleep_for(std::chrono::seconds(1));
printf("-----Test 2-----\r\n");
new HCPPTimer(NULL,std::chrono::seconds(1),[](HCPPTimer *timer)
{
printf("OneShot Timer %08X\r\n",(uint32_t)reinterpret_cast<uintptr_t>(timer));
Expand Down

0 comments on commit 730e409

Please sign in to comment.