what is the function that returns an element of a list

juhc wrote on Thursday, July 23, 2015:

Hi,

What is the function that returns an element of a list without removing it in FreeRTOS?
I need to know the first task that was added in the list pxReadyTasksLists[configMAX_PRIORITIES-1].

Thanks in advance

rtel wrote on Thursday, July 23, 2015:

The list functions are not part of the published API. I can probably tell you how to do what you want to do, but it is not clear what it is you want to do. Can you elaborate? When you say the “first task added in the list” do you mean the task that is at the front of the list, assuming tasks that were added after it are behind it in the list?

juhc wrote on Thursday, July 23, 2015:

Yes, it is the task in the front of the list.
I want to know which task the scheduler will choose to execute at the next tick interrupt.

It’s the task that has the highest priority, so if I’m not wrong, it’s the task in the front of the ready list that contains the highest priority.

davedoors wrote on Thursday, July 23, 2015:

You cant know which task the scheduler will choose to execute at the next tick interrupt until the tick interrupt executes because you cant predict if a task will unblock. Even when the tick interrupt executes you cant predict it because other interrupts might nest with the tick interrupt and unblock other tasks.

rtel wrote on Thursday, July 23, 2015:

As already said, you can’t tell which task will be selected in advance of it actually being selected, then you need to know which list to look in.

Which list to look in depends on the highest priority ready state task, which if you are using a port that supports port optimised task selection is determined by calling portGET_HIGHEST_PRIORITY() (that will use a count leading zero type instruction).

Once you know which list to look in you call listGET_OWNER_OF_NEXT_ENTRY() to obtain the next TCB.

Look at the definition of taskSELECT_HIGHEST_PRIORITY_TASK() near the top of FreeRTOS/source/tasks.c to see how the macros are used.

Regards.

juhc wrote on Monday, July 27, 2015:

Thank you for your answer.
This is exactly what I wanted.