libsaria: Begin work on a new generic idle task

I want to remove the various idle task types that have built up and
replace everything with a single idle type.  I also want the idle layer
to be the only place new tasks are allocated.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-11-23 10:02:39 -05:00 committed by Anna Schumaker
parent b6e0d6dd58
commit 5244fe9605
5 changed files with 34 additions and 30 deletions

View File

@ -5,11 +5,13 @@
namespace libsaria
{
namespace idle
{
int size();
int run_task();
void schedule(void (*)());
void queue_task(IdleTask *, bool);
void cancel_all(void *);
float progress();

View File

@ -16,16 +16,6 @@ class IdleTask
void queue_front();
};
class IdleCallback : public IdleTask
{
private:
void (*func)();
public:
IdleCallback(void (*)());
~IdleCallback();
void run_task();
};
class WriteTask : public IdleTask
{
private:

View File

@ -10,6 +10,31 @@ static deque<IdleTask *> idle_queue;
static float queued = 0.0;
static float serviced = 0.0;
class GIdleTask : public IdleTask
{
private:
void (*func)();
public:
GIdleTask(void (*)());
~GIdleTask();
void run_task();
};
GIdleTask::GIdleTask(void (*f)())
{
func = f;
}
GIdleTask::~GIdleTask()
{
}
void GIdleTask::run_task()
{
func();
}
static void do_task(IdleTask *task)
{
task->run_task();
@ -31,6 +56,12 @@ namespace libsaria
return idle_queue.size();
}
void idle::schedule(void (*func)())
{
GIdleTask *task = new GIdleTask(func);
queue_task(task, false);
}
int idle::run_task()
{
IdleTask *task;

View File

@ -23,19 +23,3 @@ bool IdleTask::should_cancel(void *data)
{
return false;
}
IdleCallback::IdleCallback(void (*f)())
{
func = f;
}
IdleCallback::~IdleCallback()
{
}
void IdleCallback::run_task()
{
func();
}

View File

@ -150,15 +150,12 @@ namespace libsaria
void library::init()
{
IdleCallback *task;
bool random = prefs::init("libsaria.library.random", true);
lib_playlist.set_flag(PL_RANDOM, random);
app::mkdir("library");
next_id = schedule_load();
task = new IdleCallback(restore_current);
task->queue();
idle::schedule(restore_current);
}
}; /* namespace: libsaria */