Author: mjg
Date: Tue Dec 17 14:53:55 2019
New Revision: 355855
URL: https://svnweb.freebsd.org/changeset/base/355855

Log:
  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.

Modified:
  head/sys/sys/pcpu.h

Modified: head/sys/sys/pcpu.h
==============================================================================
--- head/sys/sys/pcpu.h Tue Dec 17 11:03:32 2019        (r355854)
+++ head/sys/sys/pcpu.h Tue Dec 17 14:53:55 2019        (r355855)
@@ -228,28 +228,30 @@ 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);
-}
+#define zpcpu_get_cpu(base, cpu) ({                                            
        \
+       __typeof(base) _ptr = (void *)((char *)(base) + UMA_PCPU_ALLOC_SIZE * 
cpu);     \
+       _ptr;                                                                   
        \
+})
 
-static inline void *
-zpcpu_get_cpu(void *base, int cpu)
-{
-
-       return ((char *)(base) + UMA_PCPU_ALLOC_SIZE * cpu);
-}
-
 /*
  * This operation is NOT atomic and does not post any barriers.
  * If you use this the assumption is that the target CPU will not
  * 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;                                                           \
 })
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to