How to get a list of all task handles?

helliwell_cj wrote on Monday, January 04, 2016:

I’m implementing a watchdog function, whereby each task ‘checks in’ (to indicate it is still alive) by setting a flag/variable; the watchdog monitor periodically makes sure all the current tasks have checked in and, if so, resets the cpu watchdog time and clears the flags.
I’ve got the mechanism basically working, but the monitor needs to know how many and/or which tasks it should expect to hear from. Currently I’ve used uxTaskGetSystemState(), but it’s causing me to miss some UART interrupts [yes, I’m aware that this function is only recommended for debugging].
So is there a neater/faster way to get a list of task handles? I don’t need much of the stuff that uxTaskGetSystemState() does (and which presumably cause the lengthy scheduler suspension) - I just need to be able to walk through the list and examine a couple of variables of each TCB.

davedoors wrote on Monday, January 04, 2016:

uxTaskGetSystemState() is the normal way, but if it is causing a problem, then how about having your tasks register with the watchdog management task when they are create? That can be done manually by the task implementer or automatically using the trace macros that execute when a task is created and deleted.

helliwell_cj wrote on Monday, January 04, 2016:

Yes, I’d starting wondering - if there’s no other mechanism already there to use - about patching into the create/delete. I am using Trace functionality too though, so I’d need to wrap extra into the trace macros. Doing it ‘manually’ could be a bit too much of a risk [of forgetting].
I did also wonder about simply adding my own function to tasks.c - not ideal but, given that I’d need to modify the trace macros anyway, may be just as clean a solution? Bit of a headache to keep re-patching into future updates, though we won’t be upgrading the RTOS too often.

helliwell_cj wrote on Monday, January 04, 2016:

Just for potentially useful info for others:
uxTaskGetSystemState() is taking about ~2ms to execute on my system; with 10 tasks running. The bulk of this time is in finding the stacks’ high water marks (prvTaskCheckFreeStackSpace) - commenting this out drops the execution time to ~20us.