Wait for OS messages when is possible

With this change we will reduce the CPU and energy consumption levels
as now we can go to sleep when there is no OS messages left and no
timers running.
This commit is contained in:
David Capello 2018-08-17 22:09:34 -03:00
parent b275c24793
commit efffde5673
4 changed files with 22 additions and 7 deletions

2
laf

@ -1 +1 @@
Subproject commit d727d1e53ca08fd38e99dacdef5b3fd643a83b63
Subproject commit e189f488718dac5ef9a7c285f69aca724dce4714

View File

@ -189,7 +189,7 @@ Manager::~Manager()
set_mouse_cursor(kNoCursor);
// Destroy timers
Timer::checkNoTimers();
ASSERT(!Timer::haveTimers());
// Destroy filters
#ifdef _DEBUG
@ -325,8 +325,10 @@ void Manager::generateMessagesFromOSEvents()
// Events from "she" layer.
os::Event sheEvent;
for (;;) {
// bool canWait = (msg_queue.empty());
bool canWait = false;
// TODO Add timers to laf::os library so we can wait for then in
// the OS message loop.
bool canWait = (msg_queue.empty() &&
!Timer::haveRunningTimers());
m_eventQueue->getEvent(sheEvent, canWait);
if (sheEvent.type() == os::Event::None)

View File

@ -97,9 +97,21 @@ void Timer::pollTimers()
}
}
void Timer::checkNoTimers()
bool Timer::haveTimers()
{
ASSERT(timers.empty());
return !timers.empty();
}
bool Timer::haveRunningTimers()
{
if (!timers.empty()) {
for (auto timer : timers) {
if (timer && timer->isRunning()) {
return true;
}
}
}
return false;
}
} // namespace ui

View File

@ -36,7 +36,8 @@ namespace ui {
obs::signal<void()> Tick;
static void pollTimers();
static void checkNoTimers();
static bool haveTimers();
static bool haveRunningTimers();
protected:
virtual void onTick();