已更新 2025年7月

uxTaskPriorityGet()

[任务控制]

task. h

1UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );

INCLUDE_uxTaskPriorityGet
必须定义为 1,才可使用此函数。有关详细信息,请参阅 RTOS 配置文档。

获取任意任务的优先级。

参数:

  • xTask

    待查询任务的句柄。传递 NULL 句柄会返回调用任务的优先级。

返回:

  • xTask
    的优先级。

用法示例:

1void vATaskFunction( void * pvParams )
2{
3 TaskHandle_t xHandle;
4
5 ( void ) pvParams;
6
7 // Create a task, storing the handle.
8 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
9
10 // ...
11
12 // Use the handle to obtain the priority of the created task.
13 // It was created with tskIDLE_PRIORITY, but may have changed
14 // it itself.
15 if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
16 {
17 // The task has changed its priority.
18 }
19
20 // ...
21
22 // Is our priority higher than the created task?
23 if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
24 {
25 // Our priority (obtained using NULL handle) is higher.
26 }
27}