Scheduler/Thread Status #api

Casey Shea

Are there any API calls for retrieving thread and scheduler status?  I'm looking for something that would indicate the following:

  • Is the scheduler locked?
  • What is the thread status? (Ready, Waiting, Suspended)


Andy Ross

Not public ones, no.  You can check kernel/include/ksched.h for the internal API for this.  I guess the immediate question has to be "what are you trying to do"?  Recognize that any decision made on the basis of this kind of stuff is going to be inherently racy without access to the scheduler's own synchronization (though on a single CPU device, just holding an interrupt lock is enough to be safe).

Also, just to clarify: k_sched_lock() doesn't mutate "scheduler" state at all, it's implemented via a trick that essentially elevates the current thread priority to a cooperative level, preventing preemption.