diff --git a/src/gui/core/context.h b/src/gui/core/context.h index 3c806655..9df5b6c3 100755 --- a/src/gui/core/context.h +++ b/src/gui/core/context.h @@ -16,6 +16,10 @@ public: Runnable(){ run=nullptr; } + Runnable(const Runnable&b){ + run=b.run; + ID=b.ID; + } Runnable(const std::function&f){ run=f; } diff --git a/src/gui/core/uieventsource.cc b/src/gui/core/uieventsource.cc index c987a573..10ab48a4 100755 --- a/src/gui/core/uieventsource.cc +++ b/src/gui/core/uieventsource.cc @@ -29,10 +29,9 @@ int UIEventSource::handleEvents(){ if(GraphDevice::getInstance().needCompose()) GraphDevice::getInstance().ComposeSurfaces(); if(hasDelayedRunners()){ - size_t old=mRunnables.size(); RUNNER runner=mRunnables.front(); runner.run(); - mRunnables.erase(mRunnables.begin()); + mRunnables.pop_front(); } return 0; } @@ -40,7 +39,7 @@ int UIEventSource::handleEvents(){ void UIEventSource::post(Runnable& run,DWORD delayedtime){ RUNNER runner; runner.time=SystemClock::uptimeMillis()+delayedtime; - runner.run.ID=mID++; + run.ID=mID++; runner.run=run; for(auto itr=mRunnables.begin();itr!=mRunnables.end();itr++){ if(runner.timetime){ diff --git a/tests/gui/looper_tests.cc b/tests/gui/looper_tests.cc index 613a0d7a..eae4de24 100755 --- a/tests/gui/looper_tests.cc +++ b/tests/gui/looper_tests.cc @@ -5,6 +5,8 @@ #include #include #include +#include + class LOOPER:public testing::Test{ public : @@ -116,7 +118,14 @@ TEST_F(LOOPER,eventhandler){ } TEST_F(LOOPER,loop){ Looper loop(false); - loop.pollAll(1000); - loop.pollAll(1000); - loop.pollAll(1000); + UIEventSource*handler=new UIEventSource(nullptr); + loop.addEventHandler(handler); + Runnable run; + int count=0; + run=[&](){ + printf("count=%d\r\n",count++); + handler->post(run,count++); + }; + handler->post(run,10); + while(1)loop.pollAll(100); }