kernel: make sure thread priority is within valid range

The scheduler expects that all threads expect the initial idle threads
have priority in range [THREAD_MIN_SET_PRIORITY, THREAD_MAX_SET_PRIORITY].
If the requested pririty is out of range the value is clamped. Failing
with B_BAD_VALUE is probably an overkill since there isn't any real
change in the guarantees provided by the scheduler about the behavior
of such thread. Also, BeBook suggests that spawn_thread() can specify
priority 0.
This commit is contained in:
Pawel Dziepak 2014-04-18 22:14:50 +02:00
parent 2d91773d2e
commit 744dfa3c4c

View File

@ -891,6 +891,10 @@ thread_create_thread(const ThreadCreationAttributes& attributes, bool kernel)
// available for deinitialization
thread->priority = attributes.priority == -1
? B_NORMAL_PRIORITY : attributes.priority;
thread->priority = std::max(thread->priority,
(int32)THREAD_MIN_SET_PRIORITY);
thread->priority = std::min(thread->priority,
(int32)THREAD_MAX_SET_PRIORITY);
thread->state = B_THREAD_SUSPENDED;
thread->sig_block_mask = attributes.signal_mask;