[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] generic queue library for AVR GCC?
From: |
David Brown |
Subject: |
Re: [avr-gcc-list] generic queue library for AVR GCC? |
Date: |
Wed, 17 Nov 2004 10:33:03 +0100 |
> On Tuesday 16 Nov 2004 9:36 am, David Brown wrote:
> > static inline unsigned char begin_critical_section(void) {
> > unsigned char s = SREG;
> > cli();
> > return s;
> > }
> >
>
> But you still have to declare a variable to hold the return value, and
> that was what broke the #define version.
What broke the #define version was the use of two statements in the one
macro without a covering "do { } while (0)" hack.
Somewhere, a variable has to be created to hold the old SREG value. Using a
static variable won't work - it is not re-entrant safe, and if you have a
full overview over when your functions will be called, there is no need for
this protection - you can just use cli() and sli() as needed.
Some suggested macros have been putting it straight onto the stack - a risky
idea, IMHO. Others (yours, Richard? I've lost track of the thread...) have
used macros openning a new scope and explicitly defining a local variable.
Such macros have a definite advantage in that compilation will fail if you
don't match your open and close critical sections properly - however, they
would produce something horrible if you wanted to write "if (bSomeFlag)
begin_critical_section".
David
>
> Given an optimising compiler:
>
> typedef enum {cs_start, cs_end} cs_enum;
>
> static inline unsigned char critical_section(cs_enum dir)
> {
> static unsigned char s;
>
> switch(dir)
> {
> case cs_start:
> s = SREG;
> cli();
> break;
> case cs_end:
> SREG = s;
> }
> }
>
> Not much bug protection there though.
>
>
> --
> Richard Urwin
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list
>
- Re: [avr-gcc-list] generic queue library for AVR GCC?, (continued)
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Mike Panetta, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Mike Panetta, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, David Brown, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Dave Hansen, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, E. Weddington, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, E. Weddington, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Richard Urwin, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, David Brown, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, E. Weddington, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Theodore A. Roth, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?,
David Brown <=
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Bruce D. Lightner, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Andy Warner, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, rusty+avr-gcc-list, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Bruce D. Lightner, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Ben L. Titzer, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, E. Weddington, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Ben L. Titzer, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, E. Weddington, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Ben L. Titzer, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Theodore A. Roth, 2004/11/17