This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Doesn't CRITICAL_REGION_EXIT() in app_sched_event_put() have to be moved to the end of the function?

Hi,

I wonder CRITICAL_REGION_EXIT() in app_sched_event_put() have to be moved to the end of function. CRITICAL_REGION_EXIT() is called after proceeding index in current app_sched_event_put(), I think this may not keep handler and data combination.

For example, there are 2 IRQ handlers, one is A IRQ handler, the other is B IRQ handler, and A's priority is higher than B's one. Each different app_sched_event_handler is pushed in scheduler using app_sched_event_put(). When A IRQ handler is called while code(line between 196 and 197 in app_scheduler.c) after CRITICAL_REGION_EXIT() in app_sched_event_put() in B IRQ handler is being executed, the combination of handler and data must be corrupted.

app_scheduler.c

So I think CRITICAL_REGION_EXIT should be moved between line 212 and 213.

What do you thinke?

Parents
  • No. There's even a note in that file explaining this. The only critical piece is getting a spot in the queue and updating the current index, which is protected to avoid an interrupt half way through from a higher priority thread. Once you have an slot you can take your own time to fill it and it doesn't matter if you are interrupted, the next guy gets the next slot and fills it, then returns to you who finishes filling yours. Eventually you return to the main loop with one or more slots ready to go.

    The critical region is exactly only as long as it needs to be.

Reply
  • No. There's even a note in that file explaining this. The only critical piece is getting a spot in the queue and updating the current index, which is protected to avoid an interrupt half way through from a higher priority thread. Once you have an slot you can take your own time to fill it and it doesn't matter if you are interrupted, the next guy gets the next slot and fills it, then returns to you who finishes filling yours. Eventually you return to the main loop with one or more slots ready to go.

    The critical region is exactly only as long as it needs to be.

Children
Related