Disable preemption in a low prioritized thread

Discussions and support about ChibiOS/NIL, the almost nil RTOS.
Gudui
Posts: 2
Joined: Wed Dec 17, 2014 9:49 pm

Disable preemption in a low prioritized thread

Postby Gudui » Wed Dec 17, 2014 9:55 pm

Hi

I have a low prioritized thread, where I in some cases has to reboot from it. Before I reboot i have to do some preparation, and other higher prioritized tasks should not be able to preempt it while it is preparing to reboot. How can i archive this behavior? I've looked around for a command to disable preemption, but i couldn't find anything. I've tried to use the nilSysLock(), but it seems like i can't execute any code in my task excepting the nilSysUnlock().

Code: Select all

NIL_THREAD(Thread1, arg) {
  while (TRUE) {
   
    //Disable preemption here
    //Do some shutdown preparing.
   

   //shutdown

   //I've tried to use:
   nilSysLock();
   //Can't execute any of my own code, only the call to nilSysUnlock()

  }
}



Hope someone can help, thanks!
Last edited by Gudui on Wed Dec 17, 2014 11:02 pm, edited 1 time in total.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Disable preemption in a low prioritized thread

Postby Giovanni » Wed Dec 17, 2014 10:51 pm

The right way is to use nilSysLock(), I don't see why it should not work, preemption should be disabled after that.

What exactly happens after executing the lock? the debugger should tell you that.

BTW, you are using an ancient version, that function has been renamed to chSysLock() months ago.

Giovanni

Gudui
Posts: 2
Joined: Wed Dec 17, 2014 9:49 pm

Re: Disable preemption in a low prioritized thread

Postby Gudui » Wed Dec 17, 2014 11:00 pm

I'll repost with a concrete example tomorrow and debugger information. I'm using the Arduino port for my home automation project, so that is why I'm using the old function call.


Return to “ChibiOS/NIL”

Who is online

Users browsing this forum: No registered users and 5 guests