atomic.h (89eb78d542394a8461164009272ea654357795ad) | atomic.h (d0e03218ca3be48c6f7109e4810d58e7b7dd4135) |
---|---|
1/* SPDX-License-Identifier: GPL-2.0-or-later */ 2/* 3 * Generic C implementation of atomic counter operations. Do not include in 4 * machine independent code. 5 * 6 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 7 * Written by David Howells (dhowells@redhat.com) 8 */ --- 79 unchanged lines hidden (view full) --- 88 v->counter = v->counter c_op i; \ 89 raw_local_irq_restore(flags); \ 90 \ 91 return ret; \ 92} 93 94#endif /* CONFIG_SMP */ 95 | 1/* SPDX-License-Identifier: GPL-2.0-or-later */ 2/* 3 * Generic C implementation of atomic counter operations. Do not include in 4 * machine independent code. 5 * 6 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 7 * Written by David Howells (dhowells@redhat.com) 8 */ --- 79 unchanged lines hidden (view full) --- 88 v->counter = v->counter c_op i; \ 89 raw_local_irq_restore(flags); \ 90 \ 91 return ret; \ 92} 93 94#endif /* CONFIG_SMP */ 95 |
96#ifndef atomic_add_return | |
97ATOMIC_OP_RETURN(add, +) | 96ATOMIC_OP_RETURN(add, +) |
98#endif 99 100#ifndef atomic_sub_return | |
101ATOMIC_OP_RETURN(sub, -) | 97ATOMIC_OP_RETURN(sub, -) |
102#endif | |
103 | 98 |
104#ifndef atomic_fetch_add | |
105ATOMIC_FETCH_OP(add, +) | 99ATOMIC_FETCH_OP(add, +) |
106#endif 107 108#ifndef atomic_fetch_sub | |
109ATOMIC_FETCH_OP(sub, -) | 100ATOMIC_FETCH_OP(sub, -) |
110#endif 111 112#ifndef atomic_fetch_and | |
113ATOMIC_FETCH_OP(and, &) | 101ATOMIC_FETCH_OP(and, &) |
114#endif 115 116#ifndef atomic_fetch_or | |
117ATOMIC_FETCH_OP(or, |) | 102ATOMIC_FETCH_OP(or, |) |
118#endif 119 120#ifndef atomic_fetch_xor | |
121ATOMIC_FETCH_OP(xor, ^) | 103ATOMIC_FETCH_OP(xor, ^) |
122#endif | |
123 | 104 |
124#ifndef atomic_and | 105ATOMIC_OP(add, +) 106ATOMIC_OP(sub, -) |
125ATOMIC_OP(and, &) | 107ATOMIC_OP(and, &) |
126#endif 127 128#ifndef atomic_or | |
129ATOMIC_OP(or, |) | 108ATOMIC_OP(or, |) |
130#endif 131 132#ifndef atomic_xor | |
133ATOMIC_OP(xor, ^) | 109ATOMIC_OP(xor, ^) |
134#endif | |
135 136#undef ATOMIC_FETCH_OP 137#undef ATOMIC_OP_RETURN 138#undef ATOMIC_OP 139 | 110 111#undef ATOMIC_FETCH_OP 112#undef ATOMIC_OP_RETURN 113#undef ATOMIC_OP 114 |
140#ifndef atomic_read 141#define atomic_read(v) READ_ONCE((v)->counter) 142#endif | 115#define atomic_read(v) READ_ONCE((v)->counter) 116#define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i)) |
143 | 117 |
144#define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i)) 145 146static inline void atomic_add(int i, atomic_t *v) 147{ 148 atomic_add_return(i, v); 149} 150 151static inline void atomic_sub(int i, atomic_t *v) 152{ 153 atomic_sub_return(i, v); 154} 155 | |
156#define atomic_xchg(ptr, v) (xchg(&(ptr)->counter, (v))) 157#define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), (old), (new))) 158 159#endif /* __ASM_GENERIC_ATOMIC_H */ | 118#define atomic_xchg(ptr, v) (xchg(&(ptr)->counter, (v))) 119#define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), (old), (new))) 120 121#endif /* __ASM_GENERIC_ATOMIC_H */ |