Rev 1082 | Rev 1702 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1082 | Rev 1104 | ||
---|---|---|---|
Line 28... | Line 28... | ||
28 | 28 | ||
29 | #ifndef __sparc64_ATOMIC_H__ |
29 | #ifndef __sparc64_ATOMIC_H__ |
30 | #define __sparc64_ATOMIC_H__ |
30 | #define __sparc64_ATOMIC_H__ |
31 | 31 | ||
32 | #include <arch/types.h> |
32 | #include <arch/types.h> |
33 | - | ||
34 | typedef struct { volatile __u64 count; } atomic_t; |
33 | #include <typedefs.h> |
35 | 34 | ||
36 | /** Atomic add operation. |
35 | /** Atomic add operation. |
37 | * |
36 | * |
38 | * Use atomic compare and swap operation to atomically add signed value. |
37 | * Use atomic compare and swap operation to atomically add signed value. |
39 | * |
38 | * |
40 | * @param val Atomic variable. |
39 | * @param val Atomic variable. |
41 | * @param i Signed value to be added. |
40 | * @param i Signed value to be added. |
42 | * |
41 | * |
43 | * @return Value of the atomic variable as it existed before addition. |
42 | * @return Value of the atomic variable as it existed before addition. |
44 | */ |
43 | */ |
45 | static inline count_t atomic_add(atomic_t *val, int i) |
44 | static inline long atomic_add(atomic_t *val, int i) |
46 | { |
45 | { |
47 | __u64 a, b; |
46 | __u64 a, b; |
48 | volatile __u64 x = (__u64) &val->count; |
47 | volatile __u64 x = (__u64) &val->count; |
49 | 48 | ||
50 | __asm__ volatile ( |
49 | __asm__ volatile ( |
Line 60... | Line 59... | ||
60 | ); |
59 | ); |
61 | 60 | ||
62 | return a; |
61 | return a; |
63 | } |
62 | } |
64 | 63 | ||
65 | static inline count_t atomic_preinc(atomic_t *val) |
64 | static inline long atomic_preinc(atomic_t *val) |
66 | { |
65 | { |
67 | return atomic_add(val, 1) + 1; |
66 | return atomic_add(val, 1) + 1; |
68 | } |
67 | } |
69 | 68 | ||
70 | static inline count_t atomic_postinc(atomic_t *val) |
69 | static inline long atomic_postinc(atomic_t *val) |
71 | { |
70 | { |
72 | return atomic_add(val, 1); |
71 | return atomic_add(val, 1); |
73 | } |
72 | } |
74 | 73 | ||
75 | static inline count_t atomic_predec(atomic_t *val) |
74 | static inline long atomic_predec(atomic_t *val) |
76 | { |
75 | { |
77 | return atomic_add(val, -1) - 1; |
76 | return atomic_add(val, -1) - 1; |
78 | } |
77 | } |
79 | 78 | ||
80 | static inline count_t atomic_postdec(atomic_t *val) |
79 | static inline long atomic_postdec(atomic_t *val) |
81 | { |
80 | { |
82 | return atomic_add(val, -1); |
81 | return atomic_add(val, -1); |
83 | } |
82 | } |
84 | 83 | ||
85 | static inline void atomic_inc(atomic_t *val) |
84 | static inline void atomic_inc(atomic_t *val) |
Line 90... | Line 89... | ||
90 | static inline void atomic_dec(atomic_t *val) |
89 | static inline void atomic_dec(atomic_t *val) |
91 | { |
90 | { |
92 | (void) atomic_add(val, -1); |
91 | (void) atomic_add(val, -1); |
93 | } |
92 | } |
94 | 93 | ||
95 | static inline void atomic_set(atomic_t *val, __u64 i) |
- | |
96 | { |
- | |
97 | val->count = i; |
- | |
98 | } |
- | |
99 | - | ||
100 | static inline __u64 atomic_get(atomic_t *val) |
- | |
101 | { |
- | |
102 | return val->count; |
- | |
103 | } |
- | |
104 | - | ||
105 | #endif |
94 | #endif |