ocarina/lib/idle.cpp
Anna Schumaker 14879b03fd idle: Update design and unit test
I didn't have any changes to make to the IdleQueue itself, but I did
need to update the unit test and reword a few things in the design.

Signed-off-by: Anna Schuamker <schumaker.anna@gmail.com>
2014-04-06 19:57:06 -04:00

50 lines
690 B
C++

/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <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;
}