aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2019-12-17 14:53:55 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2019-12-17 14:53:55 +0000
commit98d97cdec785593d6d0c33ccef9493b3f9d3e11e (patch)
tree255352f43d980e23ce1c430aa1eb9e59a2d768b2 /sys
parent94678ee678338db8b61218a847d43e902f7e5311 (diff)
downloadsrc-98d97cdec785593d6d0c33ccef9493b3f9d3e11e.tar.gz
src-98d97cdec785593d6d0c33ccef9493b3f9d3e11e.zip
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.
Notes
Notes: svn path=/head/; revision=355855
Diffstat (limited to 'sys')
-rw-r--r--sys/sys/pcpu.h28
1 files changed, 15 insertions, 13 deletions
diff --git a/sys/sys/pcpu.h b/sys/sys/pcpu.h
index 5813b8dd0c90..afccd9ec26f2 100644
--- a/sys/sys/pcpu.h
+++ b/sys/sys/pcpu.h
@@ -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)
-{
-
- return ((char *)(base) + UMA_PCPU_ALLOC_SIZE * curcpu);
-}
-
-static inline void *
-zpcpu_get_cpu(void *base, int cpu)
-{
+#define zpcpu_get(base) ({ \
+ __typeof(base) _ptr = (void *)((char *)(base) + UMA_PCPU_ALLOC_SIZE * curcpu); \
+ _ptr; \
+})
- 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; \
})