Changes in kernel/arch/sparc64/include/atomic.h [7a0359b:986c24c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/sparc64/include/atomic.h
r7a0359b r986c24c 27 27 */ 28 28 29 /** @addtogroup sparc64 29 /** @addtogroup sparc64 30 30 * @{ 31 31 */ … … 37 37 38 38 #include <arch/barrier.h> 39 #include < typedefs.h>39 #include <arch/types.h> 40 40 #include <preemption.h> 41 #include <trace.h>42 41 43 42 /** Atomic add operation. … … 46 45 * 47 46 * @param val Atomic variable. 48 * @param i 47 * @param i Signed value to be added. 49 48 * 50 49 * @return Value of the atomic variable as it existed before addition. 51 *52 50 */ 53 NO_TRACE static inline atomic_count_t atomic_add(atomic_t *val, 54 atomic_count_t i) 51 static inline long atomic_add(atomic_t *val, int i) 55 52 { 56 atomic_count_t a; 57 atomic_count_t b; 58 53 uint64_t a, b; 54 59 55 do { 60 volatile uintptr_t ptr = (uintptr_t) &val->count;61 62 a = *(( atomic_count_t *) ptr);56 volatile uintptr_t x = (uint64_t) &val->count; 57 58 a = *((uint64_t *) x); 63 59 b = a + i; 64 65 asm volatile ( 66 "casx %0, %2, %1\n" 67 : "+m" (*((atomic_count_t *) ptr)), 68 "+r" (b) 69 : "r" (a) 70 ); 60 asm volatile ("casx %0, %2, %1\n" : "+m" (*((uint64_t *)x)), 61 "+r" (b) : "r" (a)); 71 62 } while (a != b); 72 63 73 64 return a; 74 65 } 75 66 76 NO_TRACE static inline atomic_count_tatomic_preinc(atomic_t *val)67 static inline long atomic_preinc(atomic_t *val) 77 68 { 78 69 return atomic_add(val, 1) + 1; 79 70 } 80 71 81 NO_TRACE static inline atomic_count_tatomic_postinc(atomic_t *val)72 static inline long atomic_postinc(atomic_t *val) 82 73 { 83 74 return atomic_add(val, 1); 84 75 } 85 76 86 NO_TRACE static inline atomic_count_tatomic_predec(atomic_t *val)77 static inline long atomic_predec(atomic_t *val) 87 78 { 88 79 return atomic_add(val, -1) - 1; 89 80 } 90 81 91 NO_TRACE static inline atomic_count_tatomic_postdec(atomic_t *val)82 static inline long atomic_postdec(atomic_t *val) 92 83 { 93 84 return atomic_add(val, -1); 94 85 } 95 86 96 NO_TRACEstatic inline void atomic_inc(atomic_t *val)87 static inline void atomic_inc(atomic_t *val) 97 88 { 98 89 (void) atomic_add(val, 1); 99 90 } 100 91 101 NO_TRACEstatic inline void atomic_dec(atomic_t *val)92 static inline void atomic_dec(atomic_t *val) 102 93 { 103 94 (void) atomic_add(val, -1); 104 95 } 105 96 106 NO_TRACE static inline atomic_count_ttest_and_set(atomic_t *val)97 static inline long test_and_set(atomic_t *val) 107 98 { 108 atomic_count_t v = 1; 109 volatile uintptr_t ptr = (uintptr_t) &val->count; 110 111 asm volatile ( 112 "casx %0, %2, %1\n" 113 : "+m" (*((atomic_count_t *) ptr)), 114 "+r" (v) 115 : "r" (0) 116 ); 117 99 uint64_t v = 1; 100 volatile uintptr_t x = (uint64_t) &val->count; 101 102 asm volatile ("casx %0, %2, %1\n" : "+m" (*((uint64_t *) x)), 103 "+r" (v) : "r" (0)); 104 118 105 return v; 119 106 } 120 107 121 NO_TRACEstatic inline void atomic_lock_arch(atomic_t *val)108 static inline void atomic_lock_arch(atomic_t *val) 122 109 { 123 atomic_count_t tmp1 = 1;124 atomic_count_t tmp2 = 0;125 126 volatile uintptr_t ptr = (uintptr_t) &val->count;127 110 uint64_t tmp1 = 1; 111 uint64_t tmp2 = 0; 112 113 volatile uintptr_t x = (uint64_t) &val->count; 114 128 115 preemption_disable(); 129 116 130 117 asm volatile ( 131 "0:\n" 132 "casx %0, %3, %1\n" 133 "brz %1, 2f\n" 134 "nop\n" 135 "1:\n" 136 "ldx %0, %2\n" 137 "brz %2, 0b\n" 138 "nop\n" 139 "ba,a %%xcc, 1b\n" 140 "2:\n" 141 : "+m" (*((atomic_count_t *) ptr)), 142 "+r" (tmp1), 143 "+r" (tmp2) 144 : "r" (0) 118 "0:\n" 119 "casx %0, %3, %1\n" 120 "brz %1, 2f\n" 121 "nop\n" 122 "1:\n" 123 "ldx %0, %2\n" 124 "brz %2, 0b\n" 125 "nop\n" 126 "ba %%xcc, 1b\n" 127 "nop\n" 128 "2:\n" 129 : "+m" (*((uint64_t *) x)), "+r" (tmp1), "+r" (tmp2) : "r" (0) 145 130 ); 146 131
Note:
See TracChangeset
for help on using the changeset viewer.