mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-11-29 18:59:14 +08:00
fix uieventhandler's crash(caused by runnable)
This commit is contained in:
parent
c09ccdec87
commit
c42bc74405
@ -16,6 +16,10 @@ public:
|
||||
Runnable(){
|
||||
run=nullptr;
|
||||
}
|
||||
Runnable(const Runnable&b){
|
||||
run=b.run;
|
||||
ID=b.ID;
|
||||
}
|
||||
Runnable(const std::function<void()>&f){
|
||||
run=f;
|
||||
}
|
||||
|
@ -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.time<itr->time){
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <core/systemclock.h>
|
||||
#include <cdlog.h>
|
||||
#include <functional>
|
||||
#include <core/uieventsource.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user