Convert zpcpu_* inlines to macros and add zpcpu_replace.

This allows them to do basic type casting internally, effectively relieving
consumers from having to cast on their own.
This commit is contained in:
Mateusz Guzik 2019-12-17 14:53:55 +00:00
parent 94678ee678
commit 98d97cdec7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=355855

View File

@ -228,19 +228,15 @@ extern struct pcpu *cpuid_to_pcpu[];
#define curproc (curthread->td_proc)
/* Accessor to elements allocated via UMA_ZONE_PCPU zone. */
static inline void *
zpcpu_get(void *base)
{
#define zpcpu_get(base) ({ \
__typeof(base) _ptr = (void *)((char *)(base) + UMA_PCPU_ALLOC_SIZE * curcpu); \
_ptr; \
})
return ((char *)(base) + UMA_PCPU_ALLOC_SIZE * curcpu);
}
static inline void *
zpcpu_get_cpu(void *base, int cpu)
{
return ((char *)(base) + UMA_PCPU_ALLOC_SIZE * cpu);
}
#define zpcpu_get_cpu(base, cpu) ({ \
__typeof(base) _ptr = (void *)((char *)(base) + UMA_PCPU_ALLOC_SIZE * cpu); \
_ptr; \
})
/*
* This operation is NOT atomic and does not post any barriers.
@ -248,8 +244,14 @@ zpcpu_get_cpu(void *base, int cpu)
* be modifying this variable.
* 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; \
_old; \
})
#define zpcpu_replace_cpu(base, val, cpu) ({ \
__typeof(val) _old = *(__typeof(val) *)zpcpu_get_cpu(base, cpu);\
__typeof(val) _old = *(__typeof(base))zpcpu_get_cpu(base, cpu); \
*(__typeof(val) *)zpcpu_get_cpu(base, cpu) = val; \
_old; \
})