95064e4537
I plan to introduce a new lib/ that sits between the gui and the backend files (similar to how glibc sits between the kernel and userspace). This gets the rename out of the way before I change my mind again. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
50 lines
695 B
C++
50 lines
695 B
C++
/*
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/idle.h>
|
|
|
|
#include <queue>
|
|
|
|
static std::queue<idle :: IdleBase *> idle_queue;
|
|
static float queued = 0.0;
|
|
static float serviced = 0.0;
|
|
|
|
idle :: IdleBase :: IdleBase()
|
|
{
|
|
}
|
|
|
|
idle :: IdleBase :: ~IdleBase()
|
|
{
|
|
}
|
|
|
|
void idle :: IdleBase :: schedule()
|
|
{
|
|
idle_queue.push(this);
|
|
queued++;
|
|
}
|
|
|
|
|
|
bool idle :: run_task()
|
|
{
|
|
if (idle_queue.size() > 0) {
|
|
idle_queue.front()->run();
|
|
delete idle_queue.front();
|
|
idle_queue.pop();
|
|
serviced++;
|
|
}
|
|
|
|
if (idle_queue.size() > 0)
|
|
return true;
|
|
|
|
queued = 0.0;
|
|
serviced = 0.0;
|
|
return false;
|
|
}
|
|
|
|
float idle :: get_progress()
|
|
{
|
|
if (idle_queue.size() == 0)
|
|
return 1.0;
|
|
return serviced / queued;
|
|
}
|