forked from len0rd/rockbox
lua rockevents reduce context switching for action and buttons
check if any buttons are waiting in the queue before triggering the event thread for action & button events makes button events quicker and also spend less time interrupting lua both wins Change-Id: I38346c084afdd99e4608f40b52053ee39730fb40
This commit is contained in:
parent
a511917f18
commit
1c0648c603
2 changed files with 31 additions and 16 deletions
|
@ -78,7 +78,6 @@
|
||||||
#define EV_TIMER_TICKS 5 /* timer resolution */
|
#define EV_TIMER_TICKS 5 /* timer resolution */
|
||||||
#define EV_TIMER_FREQ ((TIMER_FREQ / HZ) * EV_TIMER_TICKS)
|
#define EV_TIMER_FREQ ((TIMER_FREQ / HZ) * EV_TIMER_TICKS)
|
||||||
#define EV_TICKS (HZ / 5)
|
#define EV_TICKS (HZ / 5)
|
||||||
#define EV_INPUT (HZ / 5)
|
|
||||||
|
|
||||||
#define ENABLE_LUA_HOOK (LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT)
|
#define ENABLE_LUA_HOOK (LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT)
|
||||||
#define DISABLE_LUA_HOOK (0)
|
#define DISABLE_LUA_HOOK (0)
|
||||||
|
@ -87,7 +86,7 @@ enum {
|
||||||
THREAD_ERROR = 0x0,
|
THREAD_ERROR = 0x0,
|
||||||
/* event & suspend states */
|
/* event & suspend states */
|
||||||
THREAD_ACTEVENT = 0x1,
|
THREAD_ACTEVENT = 0x1,
|
||||||
THREAD_BUTEVENT = 0x2,
|
THREAD_BTNEVENT = 0x2,
|
||||||
THREAD_CUSTOMEVENT = 0x4,
|
THREAD_CUSTOMEVENT = 0x4,
|
||||||
THREAD_PLAYBKEVENT = 0x8,
|
THREAD_PLAYBKEVENT = 0x8,
|
||||||
THREAD_TIMEREVENT = 0x10,
|
THREAD_TIMEREVENT = 0x10,
|
||||||
|
@ -108,7 +107,7 @@ enum {
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ACTEVENT = 0,
|
ACTEVENT = 0,
|
||||||
BUTEVENT,
|
BTNEVENT,
|
||||||
CUSTOMEVENT,
|
CUSTOMEVENT,
|
||||||
PLAYBKEVENT,
|
PLAYBKEVENT,
|
||||||
TIMEREVENT,
|
TIMEREVENT,
|
||||||
|
@ -272,12 +271,16 @@ static void rev_timer_isr(void)
|
||||||
if (!is_suspend(event_flag(i)))
|
if (!is_suspend(event_flag(i)))
|
||||||
{
|
{
|
||||||
evt = ev_data.cb[i];
|
evt = ev_data.cb[i];
|
||||||
if(evt->ticks > 0 && TIME_AFTER(curr_tick, evt->next_tick))
|
|
||||||
|
if ((i == ACTEVENT || i == BTNEVENT) && rb->button_queue_count())
|
||||||
|
ev_flag |= event_flag(i); /* any buttons ready? */
|
||||||
|
else if(evt->ticks > 0 && TIME_AFTER(curr_tick, evt->next_tick))
|
||||||
ev_flag |= event_flag(i);
|
ev_flag |= event_flag(i);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_evt(ev_flag);
|
set_evt(ev_flag);
|
||||||
if (ev_data.status.event)
|
if (ev_data.status.event) /* any events ready? */
|
||||||
lua_interrupt_set(ev_data.L, ENABLE_LUA_HOOK);
|
lua_interrupt_set(ev_data.L, ENABLE_LUA_HOOK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,14 +315,23 @@ static void event_thread(void)
|
||||||
{
|
{
|
||||||
/* only send ACTION_NONE once */
|
/* only send ACTION_NONE once */
|
||||||
if (evt->id == ACTION_NONE || rb->button_status() != 0)
|
if (evt->id == ACTION_NONE || rb->button_status() != 0)
|
||||||
goto skip_callback; /* check next event */
|
{
|
||||||
|
evt->ticks = 0;
|
||||||
|
continue; /* check next event */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
evt->ticks = EV_TICKS; /* poll release event */
|
||||||
evt->id = action;
|
evt->id = action;
|
||||||
break;
|
break;
|
||||||
case BUTEVENT:
|
case BTNEVENT:
|
||||||
evt->id = rb->button_get(false);
|
evt->id = rb->button_get(false);
|
||||||
|
/* only send BUTTON_NONE once */
|
||||||
if (evt->id == BUTTON_NONE)
|
if (evt->id == BUTTON_NONE)
|
||||||
goto skip_callback; /* check next event */
|
{
|
||||||
|
evt->ticks = 0;
|
||||||
|
continue; /* check next event */
|
||||||
|
}
|
||||||
|
evt->ticks = EV_TICKS; /* poll release event */
|
||||||
break;
|
break;
|
||||||
case CUSTOMEVENT:
|
case CUSTOMEVENT:
|
||||||
case PLAYBKEVENT:
|
case PLAYBKEVENT:
|
||||||
|
@ -333,7 +345,6 @@ static void event_thread(void)
|
||||||
rev_unlock_mtx();
|
rev_unlock_mtx();
|
||||||
goto event_error;
|
goto event_error;
|
||||||
}
|
}
|
||||||
skip_callback:
|
|
||||||
evt->next_tick = *(ev_data.get_tick) + evt->ticks;
|
evt->next_tick = *(ev_data.get_tick) + evt->ticks;
|
||||||
}
|
}
|
||||||
rev_unlock_mtx(); /* we are safe to release back to main lua state */
|
rev_unlock_mtx(); /* we are safe to release back to main lua state */
|
||||||
|
@ -552,7 +563,7 @@ static unsigned int get_event_by_name(lua_State *L)
|
||||||
static const char *const ev_map[EVENT_CT] =
|
static const char *const ev_map[EVENT_CT] =
|
||||||
{
|
{
|
||||||
[ACTEVENT] = "action",
|
[ACTEVENT] = "action",
|
||||||
[BUTEVENT] = "button",
|
[BTNEVENT] = "button",
|
||||||
[CUSTOMEVENT] = "custom",
|
[CUSTOMEVENT] = "custom",
|
||||||
[PLAYBKEVENT] = "playback",
|
[PLAYBKEVENT] = "playback",
|
||||||
[TIMEREVENT] = "timer",
|
[TIMEREVENT] = "timer",
|
||||||
|
@ -580,8 +591,8 @@ static int rockev_register(lua_State *L)
|
||||||
{
|
{
|
||||||
case ACTEVENT:
|
case ACTEVENT:
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case BUTEVENT:
|
case BTNEVENT:
|
||||||
event_ticks = luaL_optinteger(L, 3, EV_INPUT);
|
event_ticks = 0; /* button events not triggered by timeout but release is*/
|
||||||
break;
|
break;
|
||||||
case CUSTOMEVENT:
|
case CUSTOMEVENT:
|
||||||
event_ticks = luaL_optinteger(L, 3, EV_TICKS);
|
event_ticks = luaL_optinteger(L, 3, EV_TICKS);
|
||||||
|
@ -607,7 +618,7 @@ static int rockev_register(lua_State *L)
|
||||||
|
|
||||||
static int rockev_suspend(lua_State *L)
|
static int rockev_suspend(lua_State *L)
|
||||||
{
|
{
|
||||||
unsigned int event; /*Arg 1 is event pass nil to suspend all */
|
unsigned int event; /*Arg 1 is event, pass nil to suspend all */
|
||||||
bool suspend = luaL_optboolean(L, 2, true);
|
bool suspend = luaL_optboolean(L, 2, true);
|
||||||
uint8_t ev_flag = THREAD_EVENT_ALL;
|
uint8_t ev_flag = THREAD_EVENT_ALL;
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,7 @@ do
|
||||||
local quit = false
|
local quit = false
|
||||||
local last_action = 0
|
local last_action = 0
|
||||||
local magnitude = 1
|
local magnitude = 1
|
||||||
local skip_ms = 1000
|
local skip_ms = 100
|
||||||
local playback
|
local playback
|
||||||
|
|
||||||
function action_event(action)
|
function action_event(action)
|
||||||
|
@ -237,11 +237,15 @@ do
|
||||||
elseif action == act.PLA_RIGHT_REPEAT then
|
elseif action == act.PLA_RIGHT_REPEAT then
|
||||||
event = pb.TRACK_FF
|
event = pb.TRACK_FF
|
||||||
audio_ff_rew(skip_ms * magnitude)
|
audio_ff_rew(skip_ms * magnitude)
|
||||||
magnitude = magnitude + 1
|
if magnitude < 300 then
|
||||||
|
magnitude = magnitude + 1
|
||||||
|
end
|
||||||
elseif action == act.PLA_LEFT_REPEAT then
|
elseif action == act.PLA_LEFT_REPEAT then
|
||||||
event = pb.TRACK_REW
|
event = pb.TRACK_REW
|
||||||
audio_ff_rew(-skip_ms * magnitude)
|
audio_ff_rew(-skip_ms * magnitude)
|
||||||
magnitude = magnitude + 1
|
if magnitude < 300 then
|
||||||
|
magnitude = magnitude + 1
|
||||||
|
end
|
||||||
elseif action == act.PLA_SELECT then
|
elseif action == act.PLA_SELECT then
|
||||||
playback = rb.audio("status")
|
playback = rb.audio("status")
|
||||||
if playback == 1 then
|
if playback == 1 then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue