From: Thierry FOURNIER Date: Mon, 16 Feb 2015 18:34:56 +0000 (+0100) Subject: MINOR: lua: core: can set the nice of the current task X-Git-Tag: v1.6-dev1~86 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37196f4ecba2179a8feb1db9f0b4d32d9daa9098;p=thirdparty%2Fhaproxy.git MINOR: lua: core: can set the nice of the current task This patch adds an LUA binding that permits to change the task priority. --- diff --git a/src/hlua.c b/src/hlua.c index 465b94bb02..4462570d5c 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -2491,6 +2491,30 @@ static int hlua_msleep(lua_State *L) return MAY_LJMP(_hlua_sleep(L, delay)); } +/* This function change the nice of the currently executed + * task. It is used set low or high priority at the current + * task. + */ +__LJMP static int hlua_setnice(lua_State *L) +{ + MAY_LJMP(check_args(L, 1, "set_nice")); + + struct hlua *hlua = hlua_gethlua(L); + int nice = MAY_LJMP(luaL_checkinteger(L, 1)); + + /* If he task is not set, I'm in a start mode. */ + if (!hlua || !hlua->task) + return 0; + + if (nice < -1024) + nice = -1024; + if (nice > 1024) + nice = 1024; + + hlua->task->nice = nice; + return 0; +} + /* This function is used as a calback of a task. It is called by the * HAProxy task subsystem when the task is awaked. The LUA runtime can * return an E_AGAIN signal, the emmiter of this signal must set a @@ -3301,6 +3325,7 @@ void hlua_init(void) hlua_class_function(gL.T, "register_task", hlua_register_task); hlua_class_function(gL.T, "register_fetches", hlua_register_fetches); hlua_class_function(gL.T, "register_converters", hlua_register_converters); + hlua_class_function(gL.T, "set_nice", hlua_setnice); hlua_class_function(gL.T, "sleep", hlua_sleep); hlua_class_function(gL.T, "msleep", hlua_msleep); hlua_class_function(gL.T, "add_acl", hlua_add_acl);