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

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

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


From: Joerg Wunsch
Subject: Re: [avr-libc-dev] New Atomic.h header?
Date: Mon, 8 Jan 2007 12:02:10 +0100
User-agent: Mutt/1.5.11

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 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. ;-)




reply via email to

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