Changeset 2bcf6c6 in mainline
- Timestamp:
- 2012-07-27T13:34:48Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4ec9ea41
- Parents:
- 3bb732b
- Location:
- kernel
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/include/atomic.h
r3bb732b r2bcf6c6 140 140 } 141 141 142 143 #define _atomic_cas_ptr_impl(pptr, exp_val, new_val, old_val, prefix) 144 asm volatile ( \ 145 prefix " cmpxchgq %[newval], %[ptr]\n" \ 146 : /* Output operands. */ \ 147 /* Old/current value is returned in eax. */ \ 148 [oldval] "=a" (old_val), \ 149 /* (*ptr) will be read and written to, hence "+" */ \ 150 [ptr] "+m" (*pptr) \ 151 : /* Input operands. */ \ 152 /* Expected value must be in eax. */ \ 153 [expval] "a" (exp_val), \ 154 /* The new value may be in any register. */ \ 155 [newval] "r" (new_val) \ 156 : "memory" \ 157 ) 158 159 /** Atomically compares and swaps the pointer at pptr. */ 160 NO_TRACE static inline void * atomic_cas_ptr(void **pptr, 161 void *exp_val, void *new_val) 162 { 163 void *old_val; 164 _atomic_cas_ptr_impl(pptr, exp_val, new_val, old_val, "lock\n"); 165 return old_val; 166 } 167 168 /** Compare-and-swap of a pointer that is atomic wrt to local cpu's interrupts. 169 * 170 * This function is NOT smp safe and is not atomic with respect to other cpus. 171 */ 172 NO_TRACE static inline void * atomic_cas_ptr_local(void **pptr, 173 void *exp_val, void *new_val) 174 { 175 void *old_val; 176 _atomic_cas_ptr_impl(pptr, exp_val, new_val, old_val, ""); 177 return old_val; 178 } 179 180 #undef _atomic_cas_ptr_impl 181 182 142 183 #endif 143 184 -
kernel/arch/ia32/include/atomic.h
r3bb732b r2bcf6c6 113 113 } 114 114 115 115 116 /** ia32 specific fast spinlock */ 116 117 NO_TRACE static inline void atomic_lock_arch(atomic_t *val) … … 142 143 } 143 144 145 146 #define _atomic_cas_ptr_impl(pptr, exp_val, new_val, old_val, prefix) \ 147 asm volatile ( \ 148 prefix " cmpxchgl %[newval], %[ptr]\n" \ 149 : /* Output operands. */ \ 150 /* Old/current value is returned in eax. */ \ 151 [oldval] "=a" (old_val), \ 152 /* (*ptr) will be read and written to, hence "+" */ \ 153 [ptr] "+m" (*pptr) \ 154 : /* Input operands. */ \ 155 /* Expected value must be in eax. */ \ 156 [expval] "a" (exp_val), \ 157 /* The new value may be in any register. */ \ 158 [newval] "r" (new_val) \ 159 : "memory" \ 160 ) 161 162 /** Atomically compares and swaps the pointer at pptr. */ 163 NO_TRACE static inline void * atomic_cas_ptr(void **pptr, 164 void *exp_val, void *new_val) 165 { 166 void *old_val; 167 _atomic_cas_ptr_impl(pptr, exp_val, new_val, old_val, "lock\n"); 168 return old_val; 169 } 170 171 /** Compare-and-swap of a pointer that is atomic wrt to local cpu's interrupts. 172 * 173 * This function is NOT smp safe and is not atomic with respect to other cpus. 174 */ 175 NO_TRACE static inline void * atomic_cas_ptr_local(void **pptr, 176 void *exp_val, void *new_val) 177 { 178 void *old_val; 179 _atomic_cas_ptr_impl(pptr, exp_val, new_val, old_val, ""); 180 return old_val; 181 } 182 183 #undef _atomic_cas_ptr_impl 184 144 185 #endif 145 186 -
kernel/test/atomic/atomic1.c
r3bb732b r2bcf6c6 60 60 return "Failed atomic_get() after atomic_predec()"; 61 61 62 void *ptr = 0; 63 void *a_ptr = &a; 64 if (atomic_cas_ptr(&ptr, 0, a_ptr) != 0) 65 return "Failed atomic_cas_ptr(): bad return value"; 66 if (ptr != a_ptr) 67 return "Failed atomic_cas_ptr(): bad pointer value"; 68 if (atomic_cas_ptr(&ptr, 0, 0) != a_ptr) 69 return "Failed atomic_cas_ptr(): indicated change"; 70 if (ptr != a_ptr) 71 return "Failed atomic_cas_ptr(): changed the ptr"; 72 62 73 return NULL; 63 74 }
Note:
See TracChangeset
for help on using the changeset viewer.