Page 1 of 1

How to get pointer to IDLE thread?

Posted: Fri May 11, 2012 7:20 am
by barthess
Hi Giovanni,
In my project I need to roughly estimate "CPU usage". It can be calculated from Idle ticks and whole system ticks. For this purpose I need to get pointer to Idle thread. Is there elegant way to get Idle thread pointer? I have found 2:
1) Iterate through thread registry and search name "idle". Ugly.
2) Modify chSysInit() function to return idle thread pointer.

Also, I can realize second way and commit to trunk if it acceptable.

Re: How to get pointer to IDLE thread?

Posted: Fri May 11, 2012 7:38 am
by Giovanni
Hi,

There is already a macro chSysGetIdleThread() but it only works when the idle thread is the one internally defined.

Probably it would be better to change it to use "rlist.r_queue.r_prev", it always point to the idle thread because it is at the lowest priority and always ready.

Giovanni