Tidy up zpcpu_replace*

- only compute the target address once
- remove spurious type casting, zpcpu_get already return the correct type

While here add missing newlines to other routines.
This commit is contained in:
Mateusz Guzik 2020-02-10 13:52:25 +00:00
parent 0b40dcbe32
commit d1e5538758

View File

@ -245,32 +245,41 @@ extern struct pcpu *cpuid_to_pcpu[];
* If you need atomicity use xchg.
* */
#define zpcpu_replace(base, val) ({ \
__typeof(val) _old = *(__typeof(base))zpcpu_get(base); \
*(__typeof(val) *)zpcpu_get(base) = val; \
__typeof(val) *_ptr = zpcpu_get(base); \
__typeof(val) _old; \
\
_old = *_ptr; \
*_ptr = val; \
_old; \
})
#define zpcpu_replace_cpu(base, val, cpu) ({ \
__typeof(val) _old = *(__typeof(base))zpcpu_get_cpu(base, cpu); \
*(__typeof(val) *)zpcpu_get_cpu(base, cpu) = val; \
__typeof(val) *_ptr = zpcpu_get_cpu(base, cpu); \
__typeof(val) _old; \
\
_old = *_ptr; \
*_ptr = val; \
_old; \
})
#define zpcpu_set_protected(base, val) ({ \
MPASS(curthread->td_critnest > 0); \
__typeof(val) *_ptr = zpcpu_get(base); \
\
*_ptr = (val); \
})
#define zpcpu_add_protected(base, val) ({ \
MPASS(curthread->td_critnest > 0); \
__typeof(val) *_ptr = zpcpu_get(base); \
\
*_ptr += (val); \
})
#define zpcpu_sub_protected(base, val) ({ \
MPASS(curthread->td_critnest > 0); \
__typeof(val) *_ptr = zpcpu_get(base); \
\
*_ptr -= (val); \
})