diff --git a/src/win/util.c b/src/win/util.c index 57061bf8d..da1238d37 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -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; } diff --git a/test/test-thread-priority.c b/test/test-thread-priority.c index 3f57d128e..f1e4f9a70 100644 --- a/test/test-thread-priority.c +++ b/test/test-thread-priority.c @@ -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