1
/* MN10300 Atomic counter operations
3
* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4
* Written by David Howells (dhowells@redhat.com)
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public Licence
8
* as published by the Free Software Foundation; either version
9
* 2 of the Licence, or (at your option) any later version.
19
* Atomic operations that C can't guarantee us. Useful for
20
* resource counting etc..
24
* Make sure gcc doesn't try to be clever and move things around
25
* on us. We need to use _exactly_ the address the user gave us,
26
* not some alias that contains the same information.
32
#define ATOMIC_INIT(i) { (i) }
37
* atomic_read - read atomic variable
38
* @v: pointer of type atomic_t
40
* Atomically reads the value of @v. Note that the guaranteed
41
* useful range of an atomic_t is only 24 bits.
43
#define atomic_read(v) ((v)->counter)
46
* atomic_set - set atomic variable
47
* @v: pointer of type atomic_t
50
* Atomically sets the value of @v to @i. Note that the guaranteed
51
* useful range of an atomic_t is only 24 bits.
53
#define atomic_set(v, i) (((v)->counter) = (i))
55
#include <asm/system.h>
58
* atomic_add_return - add integer to atomic variable
59
* @i: integer value to add
60
* @v: pointer of type atomic_t
62
* Atomically adds @i to @v and returns the result
63
* Note that the guaranteed useful range of an atomic_t is only 24 bits.
65
static inline int atomic_add_return(int i, atomic_t *v)
70
local_irq_save(flags);
74
local_irq_restore(flags);
80
* atomic_sub_return - subtract integer from atomic variable
81
* @i: integer value to subtract
82
* @v: pointer of type atomic_t
84
* Atomically subtracts @i from @v and returns the result
85
* Note that the guaranteed useful range of an atomic_t is only 24 bits.
87
static inline int atomic_sub_return(int i, atomic_t *v)
92
local_irq_save(flags);
96
local_irq_restore(flags);
101
static inline int atomic_add_negative(int i, atomic_t *v)
103
return atomic_add_return(i, v) < 0;
106
static inline void atomic_add(int i, atomic_t *v)
108
atomic_add_return(i, v);
111
static inline void atomic_sub(int i, atomic_t *v)
113
atomic_sub_return(i, v);
116
static inline void atomic_inc(atomic_t *v)
118
atomic_add_return(1, v);
121
static inline void atomic_dec(atomic_t *v)
123
atomic_sub_return(1, v);
126
#define atomic_dec_return(v) atomic_sub_return(1, (v))
127
#define atomic_inc_return(v) atomic_add_return(1, (v))
129
#define atomic_sub_and_test(i, v) (atomic_sub_return((i), (v)) == 0)
130
#define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
131
#define atomic_inc_and_test(v) (atomic_add_return(1, (v)) == 0)
133
#define atomic_add_unless(v, a, u) \
136
c = atomic_read(v); \
137
while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \
142
#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
144
static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
149
local_irq_save(flags);
151
local_irq_restore(flags);
154
#define atomic_xchg(ptr, v) (xchg(&(ptr)->counter, (v)))
155
#define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), (old), (new)))
157
/* Atomic operations are already serializing on MN10300??? */
158
#define smp_mb__before_atomic_dec() barrier()
159
#define smp_mb__after_atomic_dec() barrier()
160
#define smp_mb__before_atomic_inc() barrier()
161
#define smp_mb__after_atomic_inc() barrier()
163
#include <asm-generic/atomic.h>
165
#endif /* __KERNEL__ */
166
#endif /* _ASM_ATOMIC_H */