Code Confidencebuild 3.0.0.201402161939

Thread priorities

Name

cyg_thread_get_priority, cyg_thread_get_current_priority, cyg_thread_set_priority -- Examine and manipulate thread priorities

Synopsis

#include <cyg/kernel/kapi.h>
        

cyg_priority_t cyg_thread_get_priority(cyg_handle_t thread);

cyg_priority_t cyg_thread_get_current_priority(cyg_handle_t thread);

void cyg_thread_set_priority(cyg_handle_t thread, cyg_priority_t priority);

Description

Typical schedulers use the concept of a thread priority to determine which thread should run next. Exactly what this priority consists of will depend on the scheduler, but a typical implementation would be a small integer in the range 0 to 31, with 0 being the highest priority. Usually only the idle thread will run at the lowest priority. The exact number of priority levels available depends on the configuration, typically the option CYGNUM_KERNEL_SCHED_PRIORITIES.

cyg_thread_get_priority can be used to determine the priority of a thread, or more correctly the value last used in a cyg_thread_set_priority call or when the thread was first created. In some circumstances it is possible that the thread is actually running at a higher priority. For example, if it owns a mutex and priority ceilings or inheritance is being used to prevent priority inversion problems, then the thread's priority may have been boosted temporarily. cyg_thread_get_current_priority returns the real current priority.

In many applications appropriate thread priorities can be determined and allocated statically. However, if it is necessary for a thread's priority to change at run-time then the cyg_thread_set_priority function provides this functionality.

Valid contexts

cyg_thread_get_priority and cyg_thread_get_current_priority can be called from thread or DSR context, although the latter is rarely useful. cyg_thread_set_priority should also only be called from thread context.