[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: Joerg Wunsch
Subject: Re: [avr-gcc-list] race condition in sleep_mode()
Date: Wed, 28 Dec 2005 19:34:57 +0100 (MET)

Andreas Kaiser <address@hidden> wrote:

> Why split SEI and SLEEP in two, if the code only works correctly if
> they are adjacent instructions at the machine level?

This is not true.

For many applications, it is simply viable to have interrupts enabled
all the time, and then just execute a SLEEP instruction when no more
work can be done at some point, as they probably just don't care
whether some interrupt is still handled before the sleep, or awakes
the device from sleep.  In that case, it's not required at all that
the SEI and SLEEP instructions are adjacent.  This typical case is
normally handled by the sleep_mode() macro.

The example just demonstrates the manual method where *any* sequence
of instructions is determined by the C programmer, and where it was
deemed crucial by the programmer that the SLEEP instruction will
really be entered before any interrupt could get a chance to hit
before (IOW, your situation).  In my opinion, it would violate POLA to
suddenly have an SEI implied by sleep_cpu().  If people really think
this should be a single macro, then the name should reflect this, like
enable_interrupts_and_sleep() (but I'd prefer the name to start with

cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)

reply via email to

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