~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/futex/include/atomic.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0-or-later */
  2 /******************************************************************************
  3  *
  4  *   Copyright © International Business Machines  Corp., 2009
  5  *
  6  * DESCRIPTION
  7  *      GCC atomic builtin wrappers
  8  *      http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html
  9  *
 10  * AUTHOR
 11  *      Darren Hart <dvhart@linux.intel.com>
 12  *
 13  * HISTORY
 14  *      2009-Nov-17: Initial version by Darren Hart <dvhart@linux.intel.com>
 15  *
 16  *****************************************************************************/
 17 
 18 #ifndef _ATOMIC_H
 19 #define _ATOMIC_H
 20 
 21 typedef struct {
 22         volatile int val;
 23 } atomic_t;
 24 
 25 #define ATOMIC_INITIALIZER { 0 }
 26 
 27 /**
 28  * atomic_cmpxchg() - Atomic compare and exchange
 29  * @uaddr:      The address of the futex to be modified
 30  * @oldval:     The expected value of the futex
 31  * @newval:     The new value to try and assign the futex
 32  *
 33  * Return the old value of addr->val.
 34  */
 35 static inline int
 36 atomic_cmpxchg(atomic_t *addr, int oldval, int newval)
 37 {
 38         return __sync_val_compare_and_swap(&addr->val, oldval, newval);
 39 }
 40 
 41 /**
 42  * atomic_inc() - Atomic incrememnt
 43  * @addr:       Address of the variable to increment
 44  *
 45  * Return the new value of addr->val.
 46  */
 47 static inline int
 48 atomic_inc(atomic_t *addr)
 49 {
 50         return __sync_add_and_fetch(&addr->val, 1);
 51 }
 52 
 53 /**
 54  * atomic_dec() - Atomic decrement
 55  * @addr:       Address of the variable to decrement
 56  *
 57  * Return the new value of addr-val.
 58  */
 59 static inline int
 60 atomic_dec(atomic_t *addr)
 61 {
 62         return __sync_sub_and_fetch(&addr->val, 1);
 63 }
 64 
 65 /**
 66  * atomic_set() - Atomic set
 67  * @addr:       Address of the variable to set
 68  * @newval:     New value for the atomic_t
 69  *
 70  * Return the new value of addr->val.
 71  */
 72 static inline int
 73 atomic_set(atomic_t *addr, int newval)
 74 {
 75         addr->val = newval;
 76         return newval;
 77 }
 78 
 79 #endif
 80 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php