0
0
mirror of https://github.com/zeromq/libzmq.git synced 2025-01-14 01:37:56 +08:00

When setting thread priority, always set the value to zero when the policy is not compatible. Also, only call nice when the priority is set to a strictly positive value.

This commit is contained in:
Guillaume DELACOURT 2023-05-23 16:40:46 +02:00 committed by Luca Boccassi
parent 5bf04ee2ff
commit 797c7f09f8
2 changed files with 10 additions and 10 deletions

View File

@ -66,7 +66,8 @@ The 'ZMQ_THREAD_PRIORITY' argument sets scheduling priority for
internal context's thread pool. This option is not available on windows.
Supported values for this option depend on chosen scheduling policy.
On Linux, when the scheduler policy is SCHED_OTHER, SCHED_IDLE or SCHED_BATCH, the OS scheduler
will not use the thread priority but rather the thread "nice value"; in such cases
will not use the thread priority but rather the thread "nice value"; in such cases,
if 'ZMQ_THREAD_PRIORITY' is set to a strictly positive value,
the system call "nice" will be used to set the nice value to -20 (max priority) instead of
adjusting the thread priority (which must be zero for those scheduling policies).
Details can be found in sched.h file, or at http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html.

View File

@ -292,14 +292,12 @@ void zmq::thread_t::
bool use_nice_instead_priority =
(policy != SCHED_FIFO) && (policy != SCHED_RR);
if (_thread_priority != ZMQ_THREAD_PRIORITY_DFLT) {
if (use_nice_instead_priority)
param.sched_priority =
0; // this is the only supported priority for most scheduling policies
else
else if (_thread_priority != ZMQ_THREAD_PRIORITY_DFLT)
param.sched_priority =
_thread_priority; // user should provide a value between 1 and 99
}
#ifdef __NetBSD__
if (policy == SCHED_OTHER)
@ -318,7 +316,8 @@ void zmq::thread_t::
#if !defined ZMQ_HAVE_VXWORKS
if (use_nice_instead_priority
&& _thread_priority != ZMQ_THREAD_PRIORITY_DFLT) {
&& _thread_priority != ZMQ_THREAD_PRIORITY_DFLT
&& _thread_priority > 0) {
// assume the user wants to decrease the thread's nice value
// i.e., increase the chance of this thread being scheduled: try setting that to
// maximum priority.