]>
git.proxmox.com Git - mirror_ubuntu-kernels.git/blob - tools/testing/selftests/futex/include/atomic.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /******************************************************************************
4 * Copyright © International Business Machines Corp., 2009
7 * GCC atomic builtin wrappers
8 * http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html
11 * Darren Hart <dvhart@linux.intel.com>
14 * 2009-Nov-17: Initial version by Darren Hart <dvhart@linux.intel.com>
16 *****************************************************************************/
25 #define ATOMIC_INITIALIZER { 0 }
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
33 * Return the old value of addr->val.
36 atomic_cmpxchg(atomic_t
*addr
, int oldval
, int newval
)
38 return __sync_val_compare_and_swap(&addr
->val
, oldval
, newval
);
42 * atomic_inc() - Atomic incrememnt
43 * @addr: Address of the variable to increment
45 * Return the new value of addr->val.
48 atomic_inc(atomic_t
*addr
)
50 return __sync_add_and_fetch(&addr
->val
, 1);
54 * atomic_dec() - Atomic decrement
55 * @addr: Address of the variable to decrement
57 * Return the new value of addr-val.
60 atomic_dec(atomic_t
*addr
)
62 return __sync_sub_and_fetch(&addr
->val
, 1);
66 * atomic_set() - Atomic set
67 * @addr: Address of the variable to set
68 * @newval: New value for the atomic_t
70 * Return the new value of addr->val.
73 atomic_set(atomic_t
*addr
, int newval
)