win: make uv_thread_{get,set}priority 'thread not found' error consistent

UV_ESRCH is now returned on all platforms
This commit is contained in:
Ryan Liptak 2025-05-13 15:29:57 -07:00
parent 97b243418b
commit b6d0bbe7e9
2 changed files with 15 additions and 8 deletions

View File

@ -1519,20 +1519,26 @@ int uv_os_setpriority(uv_pid_t pid, int priority) {
}
int uv_thread_getpriority(uv_thread_t tid, int* priority) {
DWORD err;
int r;
if (priority == NULL)
return UV_EINVAL;
r = GetThreadPriority(tid);
if (r == THREAD_PRIORITY_ERROR_RETURN)
return uv_translate_sys_error(GetLastError());
if (r == THREAD_PRIORITY_ERROR_RETURN) {
err = GetLastError();
if (err == ERROR_INVALID_HANDLE)
return UV_ESRCH;
return uv_translate_sys_error(err);
}
*priority = r;
return 0;
}
int uv_thread_setpriority(uv_thread_t tid, int priority) {
DWORD err;
int r;
switch (priority) {
@ -1555,8 +1561,12 @@ int uv_thread_setpriority(uv_thread_t tid, int priority) {
return 0;
}
if (r == 0)
return uv_translate_sys_error(GetLastError());
if (r == 0) {
err = GetLastError();
if (err == ERROR_INVALID_HANDLE)
return UV_ESRCH;
return uv_translate_sys_error(err);
}
return 0;
}

View File

@ -102,10 +102,7 @@ TEST_IMPL(thread_priority) {
uv_sem_destroy(&sem);
/* Now that the thread no longer exists, verify that the relevant error is returned */
#ifdef _WIN32
ASSERT_EQ(UV_EBADF, uv_thread_getpriority(task_id, &priority));
ASSERT_EQ(UV_EBADF, uv_thread_setpriority(task_id, UV_THREAD_PRIORITY_LOWEST));
#elif !defined(__ANDROID__)
#if !defined(__ANDROID__)
ASSERT_EQ(UV_ESRCH, uv_thread_getpriority(task_id, &priority));
ASSERT_EQ(UV_ESRCH, uv_thread_setpriority(task_id, UV_THREAD_PRIORITY_LOWEST));
#endif