74 lines
1.6 KiB
Plaintext
74 lines
1.6 KiB
Plaintext
== Files ==
|
|
ocarina/include/
|
|
idle.h
|
|
idle.hpp
|
|
ocarina/lib/
|
|
idle.cpp
|
|
|
|
== Depends ==
|
|
version print
|
|
|
|
Idle queue: (lib/idle.cpp)
|
|
The idle queue is used to schedule tasks to run at a later time. Idle
|
|
tasks must inherit from the IdleBase class so that multiple templated
|
|
IdleTask pointers can be placed on the same idle queue.
|
|
|
|
Creating an idle queue in idle.hpp will create a new queue for every
|
|
file that idle.h is included in. I want to have a single, shared
|
|
idle queue used by the entire application so to get around this the
|
|
IdleBase class is used and implemented in lib/idle.cpp.
|
|
|
|
- IdleBase:
|
|
class IdleBase {
|
|
private:
|
|
schedule();
|
|
|
|
public:
|
|
IdleBase();
|
|
~IdleBase();
|
|
virtual void run() = 0;
|
|
};
|
|
|
|
- IdleTask:
|
|
template <class T>
|
|
class IdleTask : IdleBase {
|
|
private:
|
|
void (*func)(T &);
|
|
T &data;
|
|
|
|
public:
|
|
IdleTask(void (*)(T &), T);
|
|
void run();
|
|
};
|
|
|
|
- Queue:
|
|
queue<IdleBase *> idle_queue;
|
|
float queued = 0.0
|
|
float serviced = 0.0
|
|
|
|
- API:
|
|
void IdleBase :: schedule();
|
|
Add the idle task to the idle queue. This should be called
|
|
by the IdleTask constructor.
|
|
queued++;
|
|
|
|
template <class T>
|
|
static inline void idle :: schedule(void (*)(T &), T);
|
|
Create a new IdleTask to run the function later.
|
|
|
|
bool idle :: run_task()
|
|
If there are tasks on the queue:
|
|
run the next task
|
|
scheduled++
|
|
If there are still tasks on the queue:
|
|
return true
|
|
else:
|
|
queued = 0
|
|
scheduled = 0
|
|
return false
|
|
|
|
float idle :: get_progress()
|
|
Return (serviced / queued) to the caller. If there are no
|
|
tasks, return 1.0 to indicate that the queue is finished (and
|
|
to avoid a divide-by-zero error).
|