14879b03fd
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>
50 lines
690 B
C++
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;
|
|
}
|