[Top][All Lists]

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

RE: [avr-libc-dev] New Atomic.h header?

From: Ron
Subject: RE: [avr-libc-dev] New Atomic.h header?
Date: Tue, 9 Jan 2007 10:35:23 +1100

> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden 
> On Behalf Of Joerg Wunsch
> Sent: Monday, 8 January 2007 10:02 PM
> To: address@hidden
> Subject: Re: [avr-libc-dev] New Atomic.h header?
> As Ron wrote:
> > I have used these two for some time now.
> > 
> > static inline STATE_REG SaveState(void)
> > {
> >     STATE_REG flags = SREG;   // get processor state
> >     cli();                    // turn off interrupts
> >     return flags;             // return machine state
> > }
> This is something like the "manual version".
> Dercy & Dean's macros are much more eloquent (IMHO) as they
> are based on a specific GCC feature (attribute cleanup) so 
> they are fully automatic and bullet-proof, no matter which 
> way you leave the protected block.  Therefore, I personally 
> like that version much more than the manual option (which 
> I've been using before to date as well). It's not easy to 
> understand at the first glimpse (until you read about all the 
> hairy details in the GCC manual), but when shipping this as 
> library code, and documenting it well, it's completely opaque 
> to the users, and "just works".

My intent was to show that the use of inline and -Os actually reduces
all that C code to just 2 instructions on entry and 1 on exit, but the
intent of the C code is still obvious to the reader. IMHO a benign use
of the compiler's powers. I have no argument against "it just works", it
is probably the wave of the future (look at .Net), but I approach its
use in small computers with some caution. Cheers, Ron.

> My only concern with it was about extending it to non-atomic
> blocks, and to blocks that force a particular state on exit 
> rather than returning to the previous state.  This is where 
> I'd like to see other developer's opinions -- it's completely 
> fine with me to supply the basic version (atomic block, 
> interrupts disabled inside the block, interrupt state 
> restored upon exit) the way Dean was suggesting, as it 
> appears to be a frequently requested item.
> -- 
> cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL
http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)

AVR-libc-dev mailing list

reply via email to

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