ocarina/core/idle.cpp
Anna Schumaker 95064e4537 Rename lib/ -> core/
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>
2014-06-05 10:21:32 -04:00

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;
}