Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump/libuv #690

Merged
merged 6 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5)
project (luv C ASM)

set(LUV_VERSION_MAJOR 1)
set(LUV_VERSION_MINOR 47)
set(LUV_VERSION_MINOR 48)
set(LUV_VERSION_PATCH 0)
set(LUV_VERSION ${LUV_VERSION_MAJOR}.${LUV_VERSION_MINOR}.${LUV_VERSION_PATCH})

Expand Down
2 changes: 1 addition & 1 deletion deps/libuv
37 changes: 37 additions & 0 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3407,6 +3407,43 @@ the number to correspond with the table keys used in `uv.thread_getaffinity` and

**Returns:** `integer` or `fail`

### `uv.thread_setpriority(thread, priority)`

> method form `thread:setpriority(priority)`

**Parameters:**
- `thread`: `luv_thread_t userdata`
- `priority`: ``number`

Sets the specified thread's scheduling priority setting. It requires elevated
privilege to set specific priorities on some platforms.

The priority can be set to the following constants.

- uv.constants.THREAD_PRIORITY_HIGHEST
- uv.constants.THREAD_PRIORITY_ABOVE_NORMAL
- uv.constants.THREAD_PRIORITY_NORMAL
- uv.constants.THREAD_PRIORITY_BELOW_NORMAL
- uv.constants.THREAD_PRIORITY_LOWEST

**Returns:** `boolean` or `fail`

### `uv.thread_getpriority(thread)

> method form `thread:getpriority()`

**Parameters:**
- `thread`: `luv_thread_t userdata`

Gets the thread's priority setting.

Retrieves the scheduling priority of the specified thread. The returned priority
value is platform dependent.

For Linux, when schedule policy is SCHED_OTHER (default), priority is 0.

**Returns:** `number` or `fail`

### `uv.thread_self()`

Returns the handle for the thread in which this is called.
Expand Down
13 changes: 13 additions & 0 deletions src/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,19 @@ static int luv_constants(lua_State* L) {
lua_setfield(L, -2, "TTY_MODE_IO");
#endif

#if LUV_UV_VERSION_GEQ(1, 48, 0)
lua_pushinteger(L, UV_THREAD_PRIORITY_HIGHEST);
lua_setfield(L, -2, "THREAD_PRIORITY_HIGHEST");
lua_pushinteger(L, UV_THREAD_PRIORITY_ABOVE_NORMAL);
lua_setfield(L, -2, "THREAD_PRIORITY_ABOVE_NORMAL");
lua_pushinteger(L, UV_THREAD_PRIORITY_NORMAL);
lua_setfield(L, -2, "THREAD_PRIORITY_NORMAL");
lua_pushinteger(L, UV_THREAD_PRIORITY_BELOW_NORMAL);
lua_setfield(L, -2, "THREAD_PRIORITY_BELOW_NORMAL");
lua_pushinteger(L, UV_THREAD_PRIORITY_LOWEST);
lua_setfield(L, -2, "THREAD_PRIORITY_LOWEST");
#endif

return 1;
}

Expand Down
4 changes: 4 additions & 0 deletions src/luv.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ static const luaL_Reg luv_functions[] = {
{"thread_setaffinity", luv_thread_setaffinity},
{"thread_getcpu", luv_thread_getcpu},
#endif
#if LUV_UV_VERSION_GEQ(1, 48, 0)
{"thread_getpriority", luv_thread_getpriority},
{"thread_setpriority", luv_thread_setpriority},
#endif

// work.c
{"new_work", luv_new_work},
Expand Down
25 changes: 25 additions & 0 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,26 @@ static int luv_thread_getcpu(lua_State* L) {
}
#endif

#if LUV_UV_VERSION_GEQ(1, 48, 0)
static int luv_thread_getpriority(lua_State* L) {
int priority;
luv_thread_t* tid = luv_check_thread(L, 1);
int ret = uv_thread_getpriority(tid->handle, &priority);
if (ret < 0) return luv_error(L, ret);
lua_pushinteger(L, priority);
return 1;
}

static int luv_thread_setpriority(lua_State* L) {
luv_thread_t* tid = luv_check_thread(L, 1);
int priority = luaL_checkinteger(L, 2);
int ret = uv_thread_setpriority(tid->handle, priority);
if (ret < 0) return luv_error(L, ret);
lua_pushboolean(L, 1);
return 1;
}
#endif

static int luv_thread_join(lua_State* L) {
luv_thread_t* tid = luv_check_thread(L, 1);
int ret = uv_thread_join(&tid->handle);
Expand Down Expand Up @@ -498,6 +518,11 @@ static const luaL_Reg luv_thread_methods[] = {
#if LUV_UV_VERSION_GEQ(1, 45, 0)
{"getaffinity", luv_thread_getaffinity},
{"setaffinity", luv_thread_setaffinity},
{"getcpu", luv_thread_getcpu},
#endif
#if LUV_UV_VERSION_GEQ(1, 48, 0)
{"getpriority", luv_thread_getpriority},
{"setpriority", luv_thread_setpriority},
#endif
{NULL, NULL}
};
Expand Down
8 changes: 7 additions & 1 deletion tests/test-misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ return require('lib/tap')(function (test)
test("uv constants", function(print, p, expect, uv)
assert(type(uv.constants)=='table')
for k, v in pairs(uv.constants) do
assert(v >= 0, k)
if k=='THREAD_PRIORITY_LOWEST' then
assert(v == -2)
elseif k=='THREAD_PRIORITY_BELOW_NORMAL' then
assert(v == -1)
else
assert(v >= 0, k)
end
end
end)

Expand Down
2 changes: 1 addition & 1 deletion tests/test-pipe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ return require('lib/tap')(function (test)
if isLinux then
assert(server:bind2('\0' .. pipe_name))
local name = server:getsockname()
assert(#name > #pipe_name + 1 )
assert(#name == #pipe_name + 1 )
assert(name:sub(1, #pipe_name + 1) == '\0' .. pipe_name)
pipe_name = name
else
Expand Down
23 changes: 23 additions & 0 deletions tests/test-thread.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,27 @@ return require('lib/tap')(function (test)
end
end, mask_size):join()
end, "1.45.0")

test("getpriority, setpriority", function(_, p, _, uv)
assert(type(uv.constants.THREAD_PRIORITY_HIGHEST)=='number')
assert(type(uv.constants.THREAD_PRIORITY_ABOVE_NORMAL)=='number')
assert(type(uv.constants.THREAD_PRIORITY_NORMAL)=='number')
assert(type(uv.constants.THREAD_PRIORITY_BELOW_NORMAL)=='number')
assert(type(uv.constants.THREAD_PRIORITY_LOWEST)=='number')

local thread = uv.new_thread(function()
local _uv = require('luv')
local self = _uv.thread_self()
local priority = assert(self:getpriority())
print('priority in thread', priority)
end)

local priority = assert(thread:getpriority())
print('default priority', priority)

assert(thread:setpriority(uv.constants.THREAD_PRIORITY_LOWEST))
priority = assert(thread:getpriority())
print('priority after change', priority)
thread:join()
end, "1.48.0")
end)
Loading