]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - tools/testing/selftests/futex/include/atomic.h
1 /******************************************************************************
3 * Copyright © International Business Machines Corp., 2009
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
11 * GCC atomic builtin wrappers
12 * http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html
15 * Darren Hart <dvhart@linux.intel.com>
18 * 2009-Nov-17: Initial version by Darren Hart <dvhart@linux.intel.com>
20 *****************************************************************************/
29 #define ATOMIC_INITIALIZER { 0 }
32 * atomic_cmpxchg() - Atomic compare and exchange
33 * @uaddr: The address of the futex to be modified
34 * @oldval: The expected value of the futex
35 * @newval: The new value to try and assign the futex
37 * Return the old value of addr->val.
40 atomic_cmpxchg(atomic_t
*addr
, int oldval
, int newval
)
42 return __sync_val_compare_and_swap(&addr
->val
, oldval
, newval
);
46 * atomic_inc() - Atomic incrememnt
47 * @addr: Address of the variable to increment
49 * Return the new value of addr->val.
52 atomic_inc(atomic_t
*addr
)
54 return __sync_add_and_fetch(&addr
->val
, 1);
58 * atomic_dec() - Atomic decrement
59 * @addr: Address of the variable to decrement
61 * Return the new value of addr-val.
64 atomic_dec(atomic_t
*addr
)
66 return __sync_sub_and_fetch(&addr
->val
, 1);
70 * atomic_set() - Atomic set
71 * @addr: Address of the variable to set
72 * @newval: New value for the atomic_t
74 * Return the new value of addr->val.
77 atomic_set(atomic_t
*addr
, int newval
)