I need a way to return the progress of the idle queue and to indicate when it is out of tasks so idle threads can stop running. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
60 lines
1.2 KiB
Plaintext
60 lines
1.2 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.
|
|
|
|
- IdleBase:
|
|
class IdleBase {
|
|
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:
|
|
deque(IdleBase *> idle_queue;
|
|
float queued = 0.0
|
|
float serviced = 0.0
|
|
|
|
- API:
|
|
template <class T>
|
|
void idle :: schedule(void (*)(T *), T *);
|
|
Schedule a function to run later (queued++). This should
|
|
be written in the idle.hpp file since it is a function
|
|
template.
|
|
|
|
bool idle :: run_task()
|
|
If there are tasks on the queue:
|
|
run the next task
|
|
scheduled++
|
|
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.
|