unix: fix uv_thread_{get,set}priority error codes (#4782)
pthread_getschedparam and pthread_setschedparam do not use errno but instead return the error code directly. https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_getschedparam.html Also include a fix to return UV_ESRCH instead of UV_EBADF on Windows, like Unix systems do.
This commit is contained in:
parent
a3b8cb9cc0
commit
2b76a4fafa
@ -1656,7 +1656,7 @@ int uv_thread_getpriority(uv_thread_t tid, int* priority) {
|
|||||||
|
|
||||||
r = pthread_getschedparam(tid, &policy, ¶m);
|
r = pthread_getschedparam(tid, &policy, ¶m);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
return UV__ERR(errno);
|
return UV__ERR(r);
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if (SCHED_OTHER == policy && pthread_equal(tid, pthread_self())) {
|
if (SCHED_OTHER == policy && pthread_equal(tid, pthread_self())) {
|
||||||
@ -1709,7 +1709,7 @@ int uv_thread_setpriority(uv_thread_t tid, int priority) {
|
|||||||
|
|
||||||
r = pthread_getschedparam(tid, &policy, ¶m);
|
r = pthread_getschedparam(tid, &policy, ¶m);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
return UV__ERR(errno);
|
return UV__ERR(r);
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
/**
|
/**
|
||||||
@ -1757,7 +1757,7 @@ int uv_thread_setpriority(uv_thread_t tid, int priority) {
|
|||||||
param.sched_priority = prio;
|
param.sched_priority = prio;
|
||||||
r = pthread_setschedparam(tid, policy, ¶m);
|
r = pthread_setschedparam(tid, policy, ¶m);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
return UV__ERR(errno);
|
return UV__ERR(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -1519,20 +1519,26 @@ int uv_os_setpriority(uv_pid_t pid, int priority) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int uv_thread_getpriority(uv_thread_t tid, int* priority) {
|
int uv_thread_getpriority(uv_thread_t tid, int* priority) {
|
||||||
|
DWORD err;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (priority == NULL)
|
if (priority == NULL)
|
||||||
return UV_EINVAL;
|
return UV_EINVAL;
|
||||||
|
|
||||||
r = GetThreadPriority(tid);
|
r = GetThreadPriority(tid);
|
||||||
if (r == THREAD_PRIORITY_ERROR_RETURN)
|
if (r == THREAD_PRIORITY_ERROR_RETURN) {
|
||||||
return uv_translate_sys_error(GetLastError());
|
err = GetLastError();
|
||||||
|
if (err == ERROR_INVALID_HANDLE)
|
||||||
|
return UV_ESRCH;
|
||||||
|
return uv_translate_sys_error(err);
|
||||||
|
}
|
||||||
|
|
||||||
*priority = r;
|
*priority = r;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uv_thread_setpriority(uv_thread_t tid, int priority) {
|
int uv_thread_setpriority(uv_thread_t tid, int priority) {
|
||||||
|
DWORD err;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
switch (priority) {
|
switch (priority) {
|
||||||
@ -1555,8 +1561,12 @@ int uv_thread_setpriority(uv_thread_t tid, int priority) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r == 0)
|
if (r == 0) {
|
||||||
return uv_translate_sys_error(GetLastError());
|
err = GetLastError();
|
||||||
|
if (err == ERROR_INVALID_HANDLE)
|
||||||
|
return UV_ESRCH;
|
||||||
|
return uv_translate_sys_error(err);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -101,5 +101,11 @@ TEST_IMPL(thread_priority) {
|
|||||||
|
|
||||||
uv_sem_destroy(&sem);
|
uv_sem_destroy(&sem);
|
||||||
|
|
||||||
|
/* Now that the thread no longer exists, verify that the relevant error is returned */
|
||||||
|
#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
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user