avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] "cli" and "sei" should clobber memory


From: Eric Weddington
Subject: Re: [avr-libc-dev] "cli" and "sei" should clobber memory
Date: Mon, 12 Dec 2005 16:59:38 -0700
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Joerg Wunsch wrote:

Sure, the memory clobber causes something like a "global volatile"
effective for *all* memory variables at these sequence points.  IOW,
it's a huge pessimization, and (IMHO) *way* worse than declaring your
single variable to be volatile, and shadow its value where the
volatileness isn't needed.

The original author of that bug report has meanwhile analyzed the
behaviour he saw as a bug in his respective version of GCC, and IIRC
admitted that no memory clobber for sei/cli is really needed.  At
least, that's what I've gathered from the previous discussion (I only
kept in mind that the bug report could basically be closed now).


This seems like the correct thing to do since we want to make sure
that accesses to variables between "cli" and "sei" are not affect by
interrupts.


No, please mark these variables as volatile.  Sure, you might need to
interrupt-protect them anyway, depending on your application.


Another possible way is to do this:

dword atomic_get_dword(volatile dword *ptr)
{
    dword ret;
    cli();
    ret = *ptr;
    sei();
    return ret;
}

Untested of course.



--
Eric Weddington




reply via email to

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