linux/include/asm-generic/local64.h

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_GENERIC_LOCAL64_H
#define _ASM_GENERIC_LOCAL64_H

#include <linux/percpu.h>
#include <asm/types.h>

/*
 * A signed long type for operations which are atomic for a single CPU.
 * Usually used in combination with per-cpu variables.
 *
 * This is the default implementation, which uses atomic64_t.  Which is
 * rather pointless.  The whole point behind local64_t is that some processors
 * can perform atomic adds and subtracts in a manner which is atomic wrt IRQs
 * running on this CPU.  local64_t allows exploitation of such capabilities.
 */

/* Implement in terms of atomics. */

#if BITS_PER_LONG == 64

#include <asm/local.h>

local64_t;

#define LOCAL64_INIT(i)

#define local64_read(l)
#define local64_set(l,i)
#define local64_inc(l)
#define local64_dec(l)
#define local64_add(i,l)
#define local64_sub(i,l)

#define local64_sub_and_test(i, l)
#define local64_dec_and_test(l)
#define local64_inc_and_test(l)
#define local64_add_negative(i, l)
#define local64_add_return(i, l)
#define local64_sub_return(i, l)
#define local64_inc_return(l)

static inline s64 local64_cmpxchg(local64_t *l, s64 old, s64 new)
{}

static inline bool local64_try_cmpxchg(local64_t *l, s64 *old, s64 new)
{}

#define local64_xchg(l, n)
#define local64_add_unless(l, _a, u)
#define local64_inc_not_zero(l)

/* Non-atomic variants, ie. preemption disabled and won't be touched
 * in interrupt, etc.  Some archs can optimize this case well. */
#define __local64_inc(l)
#define __local64_dec(l)
#define __local64_add(i,l)
#define __local64_sub(i,l)

#else /* BITS_PER_LONG != 64 */

#include <linux/atomic.h>

/* Don't use typedef: don't want them to be mixed with atomic_t's. */
typedef struct {
	atomic64_t a;
} local64_t;

#define LOCAL64_INIT

#define local64_read
#define local64_set
#define local64_inc
#define local64_dec
#define local64_add
#define local64_sub

#define local64_sub_and_test
#define local64_dec_and_test
#define local64_inc_and_test
#define local64_add_negative
#define local64_add_return
#define local64_sub_return
#define local64_inc_return

#define local64_cmpxchg
#define local64_try_cmpxchg
#define local64_xchg
#define local64_add_unless
#define local64_inc_not_zero

/* Non-atomic variants, ie. preemption disabled and won't be touched
 * in interrupt, etc.  Some archs can optimize this case well. */
#define __local64_inc
#define __local64_dec
#define __local64_add
#define __local64_sub

#endif /* BITS_PER_LONG != 64 */

#endif /* _ASM_GENERIC_LOCAL64_H */