Update to address review comments in PR #1105
This commit is contained in:
parent
4f8f192cbe
commit
9977b13bcd
|
@ -449,19 +449,19 @@ static int node_compile( lua_State* L )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Task callback handler for node.tasknow()
|
// Task callback handler for node.task.post()
|
||||||
static task_handle_t do_node_task_handle;
|
static task_handle_t do_node_task_handle;
|
||||||
static void do_node_task (task_param_t task_fn_ref, uint8_t prio)
|
static void do_node_task (task_param_t task_fn_ref, uint8_t prio)
|
||||||
{
|
{
|
||||||
UNUSED(prio);
|
UNUSED(prio);
|
||||||
lua_State* L = lua_getstate();
|
lua_State* L = lua_getstate();
|
||||||
lua_rawgeti(L, LUA_REGISTRYINDEX, (int)task_fn_ref);
|
lua_rawgeti(L, LUA_REGISTRYINDEX, (int)task_fn_ref);
|
||||||
luaL_unref(L, LUA_REGISTRYINDEX, (int)task_fn_ref);
|
luaL_unref(L, LUA_REGISTRYINDEX, (int)task_fn_ref);
|
||||||
lua_pushinteger(L, prio);
|
lua_pushinteger(L, prio);
|
||||||
lua_call(L, 1, 0);
|
lua_call(L, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lua: node.tasknow(task_cb)) -- schedule a task for execution next
|
// Lua: node.task.post([priority],task_cb) -- schedule a task for execution next
|
||||||
static int node_task_post( lua_State* L )
|
static int node_task_post( lua_State* L )
|
||||||
{
|
{
|
||||||
int n = 1, Ltype = lua_type(L, 1);
|
int n = 1, Ltype = lua_type(L, 1);
|
||||||
|
@ -472,14 +472,18 @@ static int node_task_post( lua_State* L )
|
||||||
Ltype = lua_type(L, ++n);
|
Ltype = lua_type(L, ++n);
|
||||||
}
|
}
|
||||||
luaL_argcheck(L, Ltype == LUA_TFUNCTION || Ltype == LUA_TLIGHTFUNCTION, n, "invalid function");
|
luaL_argcheck(L, Ltype == LUA_TFUNCTION || Ltype == LUA_TLIGHTFUNCTION, n, "invalid function");
|
||||||
lua_pushvalue(L, n);
|
lua_pushvalue(L, n);
|
||||||
|
|
||||||
int task_fn_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
int task_fn_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
if (!do_node_task_handle) // bind the task handle to do_node_task on 1st call
|
if (!do_node_task_handle) // bind the task handle to do_node_task on 1st call
|
||||||
do_node_task_handle = task_get_id(do_node_task);
|
do_node_task_handle = task_get_id(do_node_task);
|
||||||
|
|
||||||
task_post(priority, do_node_task_handle, (task_param_t)task_fn_ref);
|
if(!task_post(priority, do_node_task_handle, (task_param_t)task_fn_ref)) {
|
||||||
|
luaL_unref(L, LUA_REGISTRYINDEX, task_fn_ref);
|
||||||
|
luaL_error(L, "Task queue overflow. Task not posted");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lua: setcpufreq(mhz)
|
// Lua: setcpufreq(mhz)
|
||||||
|
|
|
@ -412,6 +412,8 @@ Enable a Lua callback or task to post another task request. Note that as per the
|
||||||
example multiple tasks can be posted in any task, but the highest priority is
|
example multiple tasks can be posted in any task, but the highest priority is
|
||||||
always delivered first.
|
always delivered first.
|
||||||
|
|
||||||
|
If the task queue is full then a queue full error is raised.
|
||||||
|
|
||||||
####Syntax
|
####Syntax
|
||||||
`node.task.post([task_priority], function)`
|
`node.task.post([task_priority], function)`
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue