[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: |
Richard Urwin |
Subject: |
Re: [avr-gcc-list] generic queue library for AVR GCC? |
Date: |
Tue, 16 Nov 2004 20:35:16 +0000 |
User-agent: |
KMail/1.5.3 |
On Tuesday 16 Nov 2004 7:36 pm, Geoffrey Wossum wrote:
> On Tuesday 16 November 2004 11:53 am, Richard Urwin wrote:
> > 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;
> > }
> > }
>
> This doesn't look like it would handle nested critical sections.
Correct.
> You could probably fix it in the majority of
> usages by adding a counter, though. You only store SREG in s when
> the counter is 0, and you only restore SREG when counter is being
> decremented back to 0.
Which moves away from fully optimised code.
Howabout:
typedef unsigned char critical_section;
static inline void begin_critical_section(critical_section * s) {
*s = SREG;
cli();
}
static inline void end_critical_section(critical_section * s) {
SREG = *s;
}
Then you can put all your variable definitions away at the top of the
function they are used in, and call begin and end symmetrically.
> you still have the problem of what if you put a return in statements.
> You'd leave the critical section without restoring interrupts.
That was the advantage of my previous solution that used #define to open
and close braces around the section - but that constrains you more.
--
Richard Urwin
- Re: [avr-gcc-list] generic queue library for AVR GCC?, (continued)
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Bjarne Laursen, 2004/11/16
- Re: [avr-gcc-list] generic queue library for AVR GCC?, David Brown, 2004/11/16
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Ian Caddy, 2004/11/16
- Re: [avr-gcc-list] generic queue library for AVR GCC?, David Brown, 2004/11/16
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Richard Urwin, 2004/11/16
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Geoffrey Wossum, 2004/11/16
- Re: [avr-gcc-list] generic queue library for AVR GCC?,
Richard Urwin <=
- Re: [avr-gcc-list] generic queue library for AVR GCC?, David Brown, 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/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, E. Weddington, 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?, Ben L. Titzer, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, E. Weddington, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, E. Weddington, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Geoffrey Wossum, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Mike Panetta, 2004/11/17