The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/contrib/openzfs/include/os/linux/spl/sys/atomic.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  *  Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
    3  *  Copyright (C) 2007 The Regents of the University of California.
    4  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
    5  *  Written by Brian Behlendorf <behlendorf1@llnl.gov>.
    6  *  UCRL-CODE-235197
    7  *
    8  *  This file is part of the SPL, Solaris Porting Layer.
    9  *
   10  *  The SPL is free software; you can redistribute it and/or modify it
   11  *  under the terms of the GNU General Public License as published by the
   12  *  Free Software Foundation; either version 2 of the License, or (at your
   13  *  option) any later version.
   14  *
   15  *  The SPL is distributed in the hope that it will be useful, but WITHOUT
   16  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   17  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   18  *  for more details.
   19  *
   20  *  You should have received a copy of the GNU General Public License along
   21  *  with the SPL.  If not, see <http://www.gnu.org/licenses/>.
   22  */
   23 
   24 #ifndef _SPL_ATOMIC_H
   25 #define _SPL_ATOMIC_H
   26 
   27 #include <linux/module.h>
   28 #include <linux/spinlock.h>
   29 #include <sys/types.h>
   30 
   31 /*
   32  * Map the atomic_* functions to the Linux counterparts.  This relies on the
   33  * fact that the atomic types are internally really a uint32 or uint64.  If
   34  * this were to change an alternate approach would be needed.
   35  *
   36  * N.B. Due to the limitations of the original API atomicity is not strictly
   37  * preserved when using the 64-bit functions on a 32-bit system.  In order
   38  * to support this all consumers would need to be updated to use the Linux
   39  * provided atomic_t and atomic64_t types.
   40  */
   41 #define atomic_inc_32(v)        atomic_inc((atomic_t *)(v))
   42 #define atomic_dec_32(v)        atomic_dec((atomic_t *)(v))
   43 #define atomic_add_32(v, i)     atomic_add((i), (atomic_t *)(v))
   44 #define atomic_sub_32(v, i)     atomic_sub((i), (atomic_t *)(v))
   45 #define atomic_inc_32_nv(v)     atomic_inc_return((atomic_t *)(v))
   46 #define atomic_dec_32_nv(v)     atomic_dec_return((atomic_t *)(v))
   47 #define atomic_add_32_nv(v, i)  atomic_add_return((i), (atomic_t *)(v))
   48 #define atomic_sub_32_nv(v, i)  atomic_sub_return((i), (atomic_t *)(v))
   49 #define atomic_cas_32(v, x, y)  atomic_cmpxchg((atomic_t *)(v), x, y)
   50 #define atomic_swap_32(v, x)    atomic_xchg((atomic_t *)(v), x)
   51 #define atomic_load_32(v)       atomic_read((atomic_t *)(v))
   52 #define atomic_store_32(v, x)   atomic_set((atomic_t *)(v), x)
   53 #define atomic_inc_64(v)        atomic64_inc((atomic64_t *)(v))
   54 #define atomic_dec_64(v)        atomic64_dec((atomic64_t *)(v))
   55 #define atomic_add_64(v, i)     atomic64_add((i), (atomic64_t *)(v))
   56 #define atomic_sub_64(v, i)     atomic64_sub((i), (atomic64_t *)(v))
   57 #define atomic_inc_64_nv(v)     atomic64_inc_return((atomic64_t *)(v))
   58 #define atomic_dec_64_nv(v)     atomic64_dec_return((atomic64_t *)(v))
   59 #define atomic_add_64_nv(v, i)  atomic64_add_return((i), (atomic64_t *)(v))
   60 #define atomic_sub_64_nv(v, i)  atomic64_sub_return((i), (atomic64_t *)(v))
   61 #define atomic_cas_64(v, x, y)  atomic64_cmpxchg((atomic64_t *)(v), x, y)
   62 #define atomic_swap_64(v, x)    atomic64_xchg((atomic64_t *)(v), x)
   63 #define atomic_load_64(v)       atomic64_read((atomic64_t *)(v))
   64 #define atomic_store_64(v, x)   atomic64_set((atomic64_t *)(v), x)
   65 
   66 #ifdef _LP64
   67 static __inline__ void *
   68 atomic_cas_ptr(volatile void *target,  void *cmp, void *newval)
   69 {
   70         return ((void *)atomic_cas_64((volatile uint64_t *)target,
   71             (uint64_t)cmp, (uint64_t)newval));
   72 }
   73 #else /* _LP64 */
   74 static __inline__ void *
   75 atomic_cas_ptr(volatile void *target,  void *cmp, void *newval)
   76 {
   77         return ((void *)atomic_cas_32((volatile uint32_t *)target,
   78             (uint32_t)cmp, (uint32_t)newval));
   79 }
   80 #endif /* _LP64 */
   81 
   82 #endif  /* _SPL_ATOMIC_H */

Cache object: 4d0ab0ef0acedb104907d3c7e103115e


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.