]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/frv/include/asm/atomic.h
1 /* atomic.h: atomic operation emulation for FR-V
3 * For an explanation of how atomic ops work in this arch, see:
4 * Documentation/frv/atomic-ops.txt
6 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
7 * Written by David Howells (dhowells@redhat.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
17 #include <linux/types.h>
18 #include <asm/cmpxchg.h>
19 #include <asm/barrier.h>
25 #include <asm/atomic_defs.h>
28 * Atomic operations that C can't guarantee us. Useful for
29 * resource counting etc..
31 * We do not have SMP systems, so we don't have to deal with that.
34 #define ATOMIC_INIT(i) { (i) }
35 #define atomic_read(v) READ_ONCE((v)->counter)
36 #define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i))
38 static inline int atomic_inc_return(atomic_t
*v
)
40 return __atomic_add_return(1, &v
->counter
);
43 static inline int atomic_dec_return(atomic_t
*v
)
45 return __atomic_sub_return(1, &v
->counter
);
48 static inline int atomic_add_return(int i
, atomic_t
*v
)
50 return __atomic_add_return(i
, &v
->counter
);
53 static inline int atomic_sub_return(int i
, atomic_t
*v
)
55 return __atomic_sub_return(i
, &v
->counter
);
58 static inline int atomic_add_negative(int i
, atomic_t
*v
)
60 return atomic_add_return(i
, v
) < 0;
63 static inline void atomic_add(int i
, atomic_t
*v
)
65 atomic_add_return(i
, v
);
68 static inline void atomic_sub(int i
, atomic_t
*v
)
70 atomic_sub_return(i
, v
);
73 static inline void atomic_inc(atomic_t
*v
)
78 static inline void atomic_dec(atomic_t
*v
)
83 #define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
84 #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
85 #define atomic_inc_and_test(v) (atomic_add_return(1, (v)) == 0)
94 #define ATOMIC64_INIT(i) { (i) }
96 static inline long long atomic64_read(const atomic64_t
*v
)
107 static inline void atomic64_set(atomic64_t
*v
, long long i
)
109 asm volatile("std%I0 %1,%M0"
114 static inline long long atomic64_inc_return(atomic64_t
*v
)
116 return __atomic64_add_return(1, &v
->counter
);
119 static inline long long atomic64_dec_return(atomic64_t
*v
)
121 return __atomic64_sub_return(1, &v
->counter
);
124 static inline long long atomic64_add_return(long long i
, atomic64_t
*v
)
126 return __atomic64_add_return(i
, &v
->counter
);
129 static inline long long atomic64_sub_return(long long i
, atomic64_t
*v
)
131 return __atomic64_sub_return(i
, &v
->counter
);
134 static inline long long atomic64_add_negative(long long i
, atomic64_t
*v
)
136 return atomic64_add_return(i
, v
) < 0;
139 static inline void atomic64_add(long long i
, atomic64_t
*v
)
141 atomic64_add_return(i
, v
);
144 static inline void atomic64_sub(long long i
, atomic64_t
*v
)
146 atomic64_sub_return(i
, v
);
149 static inline void atomic64_inc(atomic64_t
*v
)
151 atomic64_inc_return(v
);
154 static inline void atomic64_dec(atomic64_t
*v
)
156 atomic64_dec_return(v
);
159 #define atomic64_sub_and_test(i,v) (atomic64_sub_return((i), (v)) == 0)
160 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
161 #define atomic64_inc_and_test(v) (atomic64_inc_return((v)) == 0)
164 #define atomic_cmpxchg(v, old, new) (cmpxchg(&(v)->counter, old, new))
165 #define atomic_xchg(v, new) (xchg(&(v)->counter, new))
166 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
167 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
169 static __inline__
int __atomic_add_unless(atomic_t
*v
, int a
, int u
)
174 if (unlikely(c
== (u
)))
176 old
= atomic_cmpxchg((v
), c
, c
+ (a
));
177 if (likely(old
== c
))
184 #define ATOMIC_OP(op) \
185 static inline void atomic_##op(int i, atomic_t *v) \
187 (void)__atomic32_fetch_##op(i, &v->counter); \
190 static inline void atomic64_##op(long long i, atomic64_t *v) \
192 (void)__atomic64_fetch_##op(i, &v->counter); \
201 #endif /* _ASM_ATOMIC_H */