Rev 1890 | Rev 1903 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1890 | Rev 1902 | ||
---|---|---|---|
Line 33... | Line 33... | ||
33 | */ |
33 | */ |
34 | 34 | ||
35 | #ifndef KERN_sparc64_ATOMIC_H_ |
35 | #ifndef KERN_sparc64_ATOMIC_H_ |
36 | #define KERN_sparc64_ATOMIC_H_ |
36 | #define KERN_sparc64_ATOMIC_H_ |
37 | 37 | ||
- | 38 | #include <arch/barrier.h> |
|
38 | #include <arch/types.h> |
39 | #include <arch/types.h> |
39 | #include <typedefs.h> |
40 | #include <typedefs.h> |
40 | 41 | ||
41 | /** Atomic add operation. |
42 | /** Atomic add operation. |
42 | * |
43 | * |
Line 90... | Line 91... | ||
90 | static inline void atomic_dec(atomic_t *val) |
91 | static inline void atomic_dec(atomic_t *val) |
91 | { |
92 | { |
92 | (void) atomic_add(val, -1); |
93 | (void) atomic_add(val, -1); |
93 | } |
94 | } |
94 | 95 | ||
- | 96 | static inline long test_and_set(atomic_t *val) |
|
- | 97 | { |
|
- | 98 | uint64_t v = 1; |
|
- | 99 | ||
- | 100 | __asm__ volatile ("casx %0, %2, %1\n" : "+m" (*val), "+r" (v) : "r" (0)); |
|
- | 101 | ||
- | 102 | return v; |
|
- | 103 | } |
|
- | 104 | ||
- | 105 | static inline void atomic_lock_arch(atomic_t *val) |
|
- | 106 | { |
|
- | 107 | uint64_t tmp1 = 1; |
|
- | 108 | uint64_t tmp2; |
|
- | 109 | ||
- | 110 | __asm__ volatile ( |
|
- | 111 | "0:\n" |
|
- | 112 | "casx %0, %3, %1\n" |
|
- | 113 | "brz %1, 2f\n" |
|
- | 114 | "nop\n" |
|
- | 115 | "1:\n" |
|
- | 116 | "ldx %0, %2\n" |
|
- | 117 | "brz %2, 0b\n" |
|
- | 118 | "nop\n" |
|
- | 119 | "ba 1b\n" |
|
- | 120 | "nop\n" |
|
- | 121 | "2:\n" |
|
- | 122 | : "+m" (*val), "+r" (tmp1), "+r" (tmp2) : "r" (0) |
|
- | 123 | ); |
|
- | 124 | ||
- | 125 | /* |
|
- | 126 | * Prevent critical section code from bleeding out this way up. |
|
- | 127 | */ |
|
- | 128 | CS_ENTER_BARRIER(); |
|
- | 129 | } |
|
- | 130 | ||
95 | #endif |
131 | #endif |
96 | 132 | ||
97 | /** @} |
133 | /** @} |
98 | */ |
134 | */ |