[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] race condition in sleep_mode()

From: Andreas Kaiser
Subject: Re: [avr-gcc-list] race condition in sleep_mode()
Date: Wed, 28 Dec 2005 19:04:09 +0100

On Tue, 27 Dec 2005 23:38:52 +0100 (MET), you wrote:

>      cli();
>      if (some_condition) {
>        sleep_enable();
>        sei();
>        sleep_cpu();
>        sleep_disable();
>      }
>      sei();

Why split SEI and SLEEP in two, if the code only works correctly if
they are adjacent instructions at the machine level? IMHO it only adds
confusion, because the result is C code which is hardly understandable
without looking at the generated assembly code. If two instructions
must be used as a pair, why not generate them as a pair?

Since sleeping with interrupts disabled only makes sense if a dead
halt is desired, I recommend two functions instead, sleep_cpu  =>
SEI/SLEEP for the usual case, and halt_cpu => CLI/SLEEP for a dead
halt. Is it really necessary to have a sleep function/macro which may
be used with unknown interrupt enable state?

Gruss, Andreas

reply via email to

[Prev in Thread] Current Thread [Next in Thread]