Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_GENERIC_LOCAL_H
0003 #define _ASM_GENERIC_LOCAL_H
0004 
0005 #include <linux/percpu.h>
0006 #include <linux/atomic.h>
0007 #include <asm/types.h>
0008 
0009 /*
0010  * A signed long type for operations which are atomic for a single CPU.
0011  * Usually used in combination with per-cpu variables.
0012  *
0013  * This is the default implementation, which uses atomic_long_t.  Which is
0014  * rather pointless.  The whole point behind local_t is that some processors
0015  * can perform atomic adds and subtracts in a manner which is atomic wrt IRQs
0016  * running on this CPU.  local_t allows exploitation of such capabilities.
0017  */
0018 
0019 /* Implement in terms of atomics. */
0020 
0021 /* Don't use typedef: don't want them to be mixed with atomic_t's. */
0022 typedef struct
0023 {
0024     atomic_long_t a;
0025 } local_t;
0026 
0027 #define LOCAL_INIT(i)   { ATOMIC_LONG_INIT(i) }
0028 
0029 #define local_read(l)   atomic_long_read(&(l)->a)
0030 #define local_set(l,i)  atomic_long_set((&(l)->a),(i))
0031 #define local_inc(l)    atomic_long_inc(&(l)->a)
0032 #define local_dec(l)    atomic_long_dec(&(l)->a)
0033 #define local_add(i,l)  atomic_long_add((i),(&(l)->a))
0034 #define local_sub(i,l)  atomic_long_sub((i),(&(l)->a))
0035 
0036 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
0037 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
0038 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
0039 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
0040 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
0041 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
0042 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
0043 
0044 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
0045 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
0046 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
0047 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
0048 
0049 /* Non-atomic variants, ie. preemption disabled and won't be touched
0050  * in interrupt, etc.  Some archs can optimize this case well. */
0051 #define __local_inc(l)      local_set((l), local_read(l) + 1)
0052 #define __local_dec(l)      local_set((l), local_read(l) - 1)
0053 #define __local_add(i,l)    local_set((l), local_read(l) + (i))
0054 #define __local_sub(i,l)    local_set((l), local_read(l) - (i))
0055 
0056 #endif /* _ASM_GENERIC_LOCAL_H */