2017-11-01 15:07:57 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2015-04-07 11:53:41 -03:00
|
|
|
#ifndef __TOOLS_LINUX_ATOMIC_H
|
|
|
|
|
#define __TOOLS_LINUX_ATOMIC_H
|
|
|
|
|
|
|
|
|
|
#include <asm/atomic.h>
|
|
|
|
|
|
2022-02-02 12:03:03 +01:00
|
|
|
void atomic_long_set(atomic_long_t *v, long i);
|
|
|
|
|
|
2017-02-22 16:57:53 -03:00
|
|
|
/* atomic_cmpxchg_relaxed */
|
|
|
|
|
#ifndef atomic_cmpxchg_relaxed
|
|
|
|
|
#define atomic_cmpxchg_relaxed atomic_cmpxchg
|
|
|
|
|
#define atomic_cmpxchg_release atomic_cmpxchg
|
|
|
|
|
#endif /* atomic_cmpxchg_relaxed */
|
|
|
|
|
|
2025-08-28 12:27:58 +00:00
|
|
|
static inline bool atomic_try_cmpxchg(atomic_t *ptr, int *oldp, int new)
|
|
|
|
|
{
|
|
|
|
|
int ret, old = *oldp;
|
|
|
|
|
|
|
|
|
|
ret = atomic_cmpxchg(ptr, old, new);
|
|
|
|
|
if (ret != old)
|
|
|
|
|
*oldp = ret;
|
|
|
|
|
return ret == old;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool atomic_inc_unless_negative(atomic_t *v)
|
|
|
|
|
{
|
|
|
|
|
int c = atomic_read(v);
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
if (unlikely(c < 0))
|
|
|
|
|
return false;
|
|
|
|
|
} while (!atomic_try_cmpxchg(v, &c, c + 1));
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-07 11:53:41 -03:00
|
|
|
#endif /* __TOOLS_LINUX_ATOMIC_H */
|