at v6.18 801 B view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef __TOOLS_LINUX_ATOMIC_H 3#define __TOOLS_LINUX_ATOMIC_H 4 5#include <asm/atomic.h> 6 7void atomic_long_set(atomic_long_t *v, long i); 8 9/* atomic_cmpxchg_relaxed */ 10#ifndef atomic_cmpxchg_relaxed 11#define atomic_cmpxchg_relaxed atomic_cmpxchg 12#define atomic_cmpxchg_release atomic_cmpxchg 13#endif /* atomic_cmpxchg_relaxed */ 14 15static inline bool atomic_try_cmpxchg(atomic_t *ptr, int *oldp, int new) 16{ 17 int ret, old = *oldp; 18 19 ret = atomic_cmpxchg(ptr, old, new); 20 if (ret != old) 21 *oldp = ret; 22 return ret == old; 23} 24 25static inline bool atomic_inc_unless_negative(atomic_t *v) 26{ 27 int c = atomic_read(v); 28 29 do { 30 if (unlikely(c < 0)) 31 return false; 32 } while (!atomic_try_cmpxchg(v, &c, c + 1)); 33 34 return true; 35} 36 37#endif /* __TOOLS_LINUX_ATOMIC_H */