ocarina: Don't always run the idle task
I register the idle task when there are events in the idle queue and I remove the idle task once those events have been processed. This should cut down on CPU usage when nothing is happening.
This commit is contained in:
parent
59fbd0c696
commit
dfdb38be27
|
@ -2,5 +2,6 @@
|
|||
#define OCARINA_H
|
||||
|
||||
void ocarina_quit();
|
||||
void ocarina_idle_add();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include <libsaria/callback.h>
|
||||
#include <libsaria/print.h>
|
||||
#include <ocarina/ocarina.h>
|
||||
#include <ocarina/button.h>
|
||||
|
||||
void cb_play()
|
||||
|
@ -17,6 +18,12 @@ void cb_pause()
|
|||
show_button_list(PLAY_BUTTON_LIST);
|
||||
}
|
||||
|
||||
void cb_idle_task_queued()
|
||||
{
|
||||
print("Ocarina IDLE_TASK_QUEUED callback!");
|
||||
ocarina_idle_add();
|
||||
}
|
||||
|
||||
static void add_callback(callback_t type, void (* func)())
|
||||
{
|
||||
register_callback(type, func);
|
||||
|
@ -27,4 +34,5 @@ void setup_callbacks()
|
|||
print("Ocarina setting up callbacks");
|
||||
add_callback(PLAY, cb_play);
|
||||
add_callback(PAUSE, cb_pause);
|
||||
add_callback(IDLE_TASK_QUEUED, cb_idle_task_queued);
|
||||
}
|
||||
|
|
|
@ -14,8 +14,14 @@
|
|||
|
||||
static gboolean ocarina_idle(gpointer data)
|
||||
{
|
||||
libsaria_idle_task();
|
||||
return TRUE; /* Keep processing idle events */
|
||||
if (libsaria_idle_task() == 0)
|
||||
return FALSE; /* There are no idle events left */
|
||||
return TRUE; /* Process remaining idle events */
|
||||
}
|
||||
|
||||
void ocarina_idle_add()
|
||||
{
|
||||
g_idle_add(ocarina_idle, NULL);
|
||||
}
|
||||
|
||||
void ocarina_init(int argc, char **argv)
|
||||
|
@ -32,7 +38,6 @@ void ocarina_init(int argc, char **argv)
|
|||
window_add(vbox);
|
||||
|
||||
settings_init();
|
||||
g_idle_add(ocarina_idle, NULL);
|
||||
}
|
||||
|
||||
void ocarina_quit()
|
||||
|
|
Loading…
Reference in New Issue