Changeset 228666c in mainline for uspace/lib/libc
- Timestamp:
- 2010-02-20T18:41:53Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b03a666
- Parents:
- bc9da2a
- Location:
- uspace/lib/libc
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/arch/amd64/include/atomic.h
rbc9da2a r228666c 42 42 #include <atomicdflt.h> 43 43 44 static inline void atomic_inc(atomic_t *val) { 45 asm volatile ("lock incq %0\n" : "+m" (val->count)); 44 static inline void atomic_inc(atomic_t *val) 45 { 46 asm volatile ( 47 "lock incq %[count]\n" 48 : [count] "+m" (val->count) 49 ); 46 50 } 47 51 48 static inline void atomic_dec(atomic_t *val) { 49 asm volatile ("lock decq %0\n" : "+m" (val->count)); 52 static inline void atomic_dec(atomic_t *val) 53 { 54 asm volatile ( 55 "lock decq %[count]\n" 56 : [count] "+m" (val->count) 57 ); 50 58 } 51 59 52 static inline long atomic_postinc(atomic_t *val)60 static inline atomic_count_t atomic_postinc(atomic_t *val) 53 61 { 54 long r; 55 56 asm volatile ( 57 "movq $1, %0\n" 58 "lock xaddq %0, %1\n" 59 : "=r" (r), "+m" (val->count) 60 ); 61 62 return r; 63 } 64 65 static inline long atomic_postdec(atomic_t *val) 66 { 67 long r; 62 atomic_count_t r = 1; 68 63 69 64 asm volatile ( 70 " movq $-1, %0\n"71 "lock xaddq %0, %1\n"72 : "=r" (r), "+m" (val->count)65 "lock xaddq %[r], %[count]\n" 66 : [count] "+m" (val->count), 67 [r] "+r" (r) 73 68 ); 74 69 … … 76 71 } 77 72 78 #define atomic_preinc(val) (atomic_postinc(val) + 1) 79 #define atomic_predec(val) (atomic_postdec(val) - 1) 73 static inline atomic_count_t atomic_postdec(atomic_t *val) 74 { 75 atomic_count_t r = -1; 76 77 asm volatile ( 78 "lock xaddq %[r], %[count]\n" 79 : [count] "+m" (val->count), 80 [r] "+r" (r) 81 ); 82 83 return r; 84 } 85 86 #define atomic_preinc(val) (atomic_postinc(val) + 1) 87 #define atomic_predec(val) (atomic_postdec(val) - 1) 80 88 81 89 #endif -
uspace/lib/libc/arch/amd64/include/types.h
rbc9da2a r228666c 54 54 55 55 typedef uint64_t uintptr_t; 56 typedef uint64_t atomic_count_t; 57 typedef int64_t atomic_signed_t; 56 58 57 59 #endif -
uspace/lib/libc/arch/arm32/include/atomic.h
rbc9da2a r228666c 27 27 */ 28 28 29 /** @addtogroup libcarm32 29 /** @addtogroup libcarm32 30 30 * @{ 31 31 */ … … 38 38 39 39 #define LIBC_ARCH_ATOMIC_H_ 40 #define CAS 40 #define CAS 41 41 42 42 #include <atomicdflt.h> … … 46 46 extern uintptr_t *ras_page; 47 47 48 static inline bool cas(atomic_t *val, long ov, longnv)49 { 50 longret = 0;51 48 static inline bool cas(atomic_t *val, atomic_count_t ov, atomic_count_t nv) 49 { 50 atomic_count_t ret = 0; 51 52 52 /* 53 53 * The following instructions between labels 1 and 2 constitute a … … 75 75 : "memory" 76 76 ); 77 77 78 78 ras_page[0] = 0; 79 asm volatile ("" ::: "memory"); 79 asm volatile ( 80 "" ::: "memory" 81 ); 80 82 ras_page[1] = 0xffffffff; 81 83 82 84 return (bool) ret; 83 85 } … … 89 91 * 90 92 * @return Value after addition. 91 */ 92 static inline long atomic_add(atomic_t *val, int i) 93 { 94 long ret = 0; 95 93 * 94 */ 95 static inline atomic_count_t atomic_add(atomic_t *val, atomic_count_t i) 96 { 97 atomic_count_t ret = 0; 98 96 99 /* 97 100 * The following instructions between labels 1 and 2 constitute a … … 115 118 : [imm] "r" (i) 116 119 ); 117 120 118 121 ras_page[0] = 0; 119 asm volatile ("" ::: "memory"); 122 asm volatile ( 123 "" ::: "memory" 124 ); 120 125 ras_page[1] = 0xffffffff; 121 126 122 127 return ret; 123 128 } … … 127 132 * 128 133 * @param val Variable to be incremented. 134 * 129 135 */ 130 136 static inline void atomic_inc(atomic_t *val) … … 137 143 * 138 144 * @param val Variable to be decremented. 145 * 139 146 */ 140 147 static inline void atomic_dec(atomic_t *val) … … 148 155 * @param val Variable to be incremented. 149 156 * @return Value after incrementation. 150 */ 151 static inline long atomic_preinc(atomic_t *val) 157 * 158 */ 159 static inline atomic_count_t atomic_preinc(atomic_t *val) 152 160 { 153 161 return atomic_add(val, 1); … … 159 167 * @param val Variable to be decremented. 160 168 * @return Value after decrementation. 161 */ 162 static inline long atomic_predec(atomic_t *val) 169 * 170 */ 171 static inline atomic_count_t atomic_predec(atomic_t *val) 163 172 { 164 173 return atomic_add(val, -1); … … 170 179 * @param val Variable to be incremented. 171 180 * @return Value before incrementation. 172 */ 173 static inline long atomic_postinc(atomic_t *val) 181 * 182 */ 183 static inline atomic_count_t atomic_postinc(atomic_t *val) 174 184 { 175 185 return atomic_add(val, 1) - 1; … … 181 191 * @param val Variable to be decremented. 182 192 * @return Value before decrementation. 183 */ 184 static inline long atomic_postdec(atomic_t *val) 193 * 194 */ 195 static inline atomic_count_t atomic_postdec(atomic_t *val) 185 196 { 186 197 return atomic_add(val, -1) + 1; -
uspace/lib/libc/arch/arm32/include/types.h
rbc9da2a r228666c 55 55 56 56 typedef uint32_t uintptr_t; 57 typedef uint32_t atomic_count_t; 58 typedef int32_t atomic_signed_t; 57 59 58 60 #endif -
uspace/lib/libc/arch/ia32/include/atomic.h
rbc9da2a r228666c 40 40 #include <atomicdflt.h> 41 41 42 static inline void atomic_inc(atomic_t *val) { 43 asm volatile ("lock incl %0\n" : "+m" (val->count)); 42 static inline void atomic_inc(atomic_t *val) 43 { 44 asm volatile ( 45 "lock incl %[count]\n" 46 : [count] "+m" (val->count) 47 ); 44 48 } 45 49 46 static inline void atomic_dec(atomic_t *val) { 47 asm volatile ("lock decl %0\n" : "+m" (val->count)); 50 static inline void atomic_dec(atomic_t *val) 51 { 52 asm volatile ( 53 "lock decl %[count]\n" 54 : [count] "+m" (val->count) 55 ); 48 56 } 49 57 50 static inline long atomic_postinc(atomic_t *val)58 static inline atomic_count_t atomic_postinc(atomic_t *val) 51 59 { 52 long r; 53 54 asm volatile ( 55 "movl $1, %0\n" 56 "lock xaddl %0, %1\n" 57 : "=r" (r), "+m" (val->count) 58 ); 59 60 return r; 61 } 62 63 static inline long atomic_postdec(atomic_t *val) 64 { 65 long r; 60 atomic_count_t r = 1; 66 61 67 62 asm volatile ( 68 " movl $-1, %0\n"69 "lock xaddl %0, %1\n"70 : "=r" (r), "+m" (val->count)63 "lock xaddl %[r], %[count]\n" 64 : [count] "+m" (val->count), 65 [r] "+r" (r) 71 66 ); 72 67 … … 74 69 } 75 70 76 #define atomic_preinc(val) (atomic_postinc(val) + 1) 77 #define atomic_predec(val) (atomic_postdec(val) - 1) 71 static inline atomic_count_t atomic_postdec(atomic_t *val) 72 { 73 atomic_count_t r = -1; 74 75 asm volatile ( 76 "lock xaddl %[r], %[count]\n" 77 : [count] "+m" (val->count), 78 [r] "+r" (r) 79 ); 80 81 return r; 82 } 83 84 #define atomic_preinc(val) (atomic_postinc(val) + 1) 85 #define atomic_predec(val) (atomic_postdec(val) - 1) 78 86 79 87 #endif -
uspace/lib/libc/arch/ia32/include/types.h
rbc9da2a r228666c 54 54 55 55 typedef uint32_t uintptr_t; 56 typedef uint32_t atomic_count_t; 57 typedef int32_t atomic_signed_t; 56 58 57 59 #endif -
uspace/lib/libc/arch/ia64/include/atomic.h
rbc9da2a r228666c 42 42 static inline void atomic_inc(atomic_t *val) 43 43 { 44 longv;44 atomic_count_t v; 45 45 46 46 asm volatile ( … … 53 53 static inline void atomic_dec(atomic_t *val) 54 54 { 55 longv;55 atomic_count_t v; 56 56 57 57 asm volatile ( … … 62 62 } 63 63 64 static inline longatomic_preinc(atomic_t *val)64 static inline atomic_count_t atomic_preinc(atomic_t *val) 65 65 { 66 longv;66 atomic_count_t v; 67 67 68 68 asm volatile ( … … 75 75 } 76 76 77 static inline longatomic_predec(atomic_t *val)77 static inline atomic_count_t atomic_predec(atomic_t *val) 78 78 { 79 longv;79 atomic_count_t v; 80 80 81 81 asm volatile ( … … 88 88 } 89 89 90 static inline longatomic_postinc(atomic_t *val)90 static inline atomic_count_t atomic_postinc(atomic_t *val) 91 91 { 92 longv;92 atomic_count_t v; 93 93 94 94 asm volatile ( … … 101 101 } 102 102 103 static inline longatomic_postdec(atomic_t *val)103 static inline atomic_count_t atomic_postdec(atomic_t *val) 104 104 { 105 longv;105 atomic_count_t v; 106 106 107 107 asm volatile ( -
uspace/lib/libc/arch/ia64/include/types.h
rbc9da2a r228666c 59 59 60 60 typedef uint64_t uintptr_t; 61 typedef uint64_t atomic_count_t; 62 typedef int64_t atomic_signed_t; 61 63 62 64 typedef struct { -
uspace/lib/libc/arch/mips32/include/atomic.h
rbc9da2a r228666c 27 27 */ 28 28 29 /** @addtogroup libcmips32 29 /** @addtogroup libcmips32 30 30 * @{ 31 31 */ 32 32 /** @file 33 * @ingroup libcmips32eb 33 * @ingroup libcmips32eb 34 34 */ 35 35 … … 41 41 #include <atomicdflt.h> 42 42 43 #define atomic_inc(x) 44 #define atomic_dec(x) 43 #define atomic_inc(x) ((void) atomic_add(x, 1)) 44 #define atomic_dec(x) ((void) atomic_add(x, -1)) 45 45 46 #define atomic_postinc(x) (atomic_add(x, 1) - 1)47 #define atomic_postdec(x) (atomic_add(x, -1) + 1)46 #define atomic_postinc(x) (atomic_add(x, 1) - 1) 47 #define atomic_postdec(x) (atomic_add(x, -1) + 1) 48 48 49 #define atomic_preinc(x) atomic_add(x, 1)50 #define atomic_predec(x) atomic_add(x, -1)49 #define atomic_preinc(x) atomic_add(x, 1) 50 #define atomic_predec(x) atomic_add(x, -1) 51 51 52 52 /* Atomic addition of immediate value. 53 53 * 54 54 * @param val Memory location to which will be the immediate value added. 55 * @param i Signed immediate that will be added to *val.55 * @param i Signed immediate that will be added to *val. 56 56 * 57 57 * @return Value after addition. 58 * 58 59 */ 59 static inline long atomic_add(atomic_t *val, int i)60 static inline atomic_count_t atomic_add(atomic_t *val, atomic_count_t i) 60 61 { 61 long tmp, v; 62 62 atomic_count_t tmp; 63 atomic_count_t v; 64 63 65 asm volatile ( 64 66 "1:\n" … … 70 72 /* nop */ /* nop is inserted automatically by compiler */ 71 73 " nop\n" 72 : "=&r" (tmp), "+m" (val->count), "=&r" (v) 73 : "r" (i), "i" (0) 74 ); 75 74 : "=&r" (tmp), 75 "+m" (val->count), 76 "=&r" (v) 77 : "r" (i), 78 "i" (0) 79 ); 80 76 81 return v; 77 82 } -
uspace/lib/libc/arch/mips32/include/types.h
rbc9da2a r228666c 27 27 */ 28 28 29 /** @addtogroup libcmips32 29 /** @addtogroup libcmips32 30 30 * @{ 31 31 */ … … 55 55 56 56 typedef uint32_t uintptr_t; 57 typedef uint32_t atomic_count_t; 58 typedef int32_t atomic_signed_t; 57 59 58 60 #endif -
uspace/lib/libc/arch/ppc32/include/atomic.h
rbc9da2a r228666c 27 27 */ 28 28 29 /** @addtogroup libcppc32 29 /** @addtogroup libcppc32 30 30 * @{ 31 31 */ … … 42 42 static inline void atomic_inc(atomic_t *val) 43 43 { 44 longtmp;45 44 atomic_count_t tmp; 45 46 46 asm volatile ( 47 47 "1:\n" … … 50 50 "stwcx. %0, 0, %2\n" 51 51 "bne- 1b" 52 : "=&r" (tmp), "=m" (val->count) 53 : "r" (&val->count), "m" (val->count) 54 : "cc"); 52 : "=&r" (tmp), 53 "=m" (val->count) 54 : "r" (&val->count), 55 "m" (val->count) 56 : "cc" 57 ); 55 58 } 56 59 57 60 static inline void atomic_dec(atomic_t *val) 58 61 { 59 longtmp;60 62 atomic_count_t tmp; 63 61 64 asm volatile ( 62 65 "1:\n" 63 66 "lwarx %0, 0, %2\n" 64 67 "addic %0, %0, -1\n" 65 "stwcx. 68 "stwcx. %0, 0, %2\n" 66 69 "bne- 1b" 67 : "=&r" (tmp), "=m" (val->count) 68 : "r" (&val->count), "m" (val->count) 69 : "cc"); 70 : "=&r" (tmp), 71 "=m" (val->count) 72 : "r" (&val->count), 73 "m" (val->count) 74 : "cc" 75 ); 70 76 } 71 77 72 static inline longatomic_postinc(atomic_t *val)78 static inline atomic_count_t atomic_postinc(atomic_t *val) 73 79 { 74 80 atomic_inc(val); … … 76 82 } 77 83 78 static inline longatomic_postdec(atomic_t *val)84 static inline atomic_count_t atomic_postdec(atomic_t *val) 79 85 { 80 86 atomic_dec(val); … … 82 88 } 83 89 84 static inline longatomic_preinc(atomic_t *val)90 static inline atomic_count_t atomic_preinc(atomic_t *val) 85 91 { 86 92 atomic_inc(val); … … 88 94 } 89 95 90 static inline longatomic_predec(atomic_t *val)96 static inline atomic_count_t atomic_predec(atomic_t *val) 91 97 { 92 98 atomic_dec(val); -
uspace/lib/libc/arch/ppc32/include/types.h
rbc9da2a r228666c 27 27 */ 28 28 29 /** @addtogroup libcppc32 29 /** @addtogroup libcppc32 30 30 * @{ 31 31 */ … … 54 54 55 55 typedef uint32_t uintptr_t; 56 typedef uint32_t atomic_count_t; 57 typedef int32_t atomic_signed_t; 56 58 57 59 #endif -
uspace/lib/libc/arch/sparc64/include/atomic.h
rbc9da2a r228666c 46 46 * 47 47 * @param val Atomic variable. 48 * @param i Signed value to be added.48 * @param i Signed value to be added. 49 49 * 50 50 * @return Value of the atomic variable as it existed before addition. 51 * 51 52 */ 52 static inline long atomic_add(atomic_t *val, int i)53 static inline atomic_count_t atomic_add(atomic_t *val, atomic_count_t i) 53 54 { 54 uint64_t a, b; 55 55 atomic_count_t a; 56 atomic_count_t b; 57 56 58 do { 57 volatile uintptr_t x = (uint64_t) &val->count;58 59 a = *(( uint64_t *) x);59 volatile uintptr_t ptr = (uintptr_t) &val->count; 60 61 a = *((atomic_count_t *) ptr); 60 62 b = a + i; 61 asm volatile ("casx %0, %2, %1\n" : "+m" (*((uint64_t *)x)), "+r" (b) : "r" (a)); 63 64 asm volatile ( 65 "casx %0, %2, %1\n" 66 : "+m" (*((atomic_count_t *) ptr)), 67 "+r" (b) 68 : "r" (a) 69 ); 62 70 } while (a != b); 63 71 64 72 return a; 65 73 } 66 74 67 static inline longatomic_preinc(atomic_t *val)75 static inline atomic_count_t atomic_preinc(atomic_t *val) 68 76 { 69 77 return atomic_add(val, 1) + 1; 70 78 } 71 79 72 static inline longatomic_postinc(atomic_t *val)80 static inline atomic_count_t atomic_postinc(atomic_t *val) 73 81 { 74 82 return atomic_add(val, 1); 75 83 } 76 84 77 static inline longatomic_predec(atomic_t *val)85 static inline atomic_count_t atomic_predec(atomic_t *val) 78 86 { 79 87 return atomic_add(val, -1) - 1; 80 88 } 81 89 82 static inline longatomic_postdec(atomic_t *val)90 static inline atomic_count_t atomic_postdec(atomic_t *val) 83 91 { 84 92 return atomic_add(val, -1); -
uspace/lib/libc/arch/sparc64/include/types.h
rbc9da2a r228666c 54 54 55 55 typedef uint64_t uintptr_t; 56 typedef uint64_t atomic_count_t; 57 typedef int64_t atomic_signed_t; 56 58 57 59 #endif -
uspace/lib/libc/generic/futex.c
rbc9da2a r228666c 68 68 int futex_down(futex_t *futex) 69 69 { 70 if ( atomic_predec(futex) < 0)70 if ((atomic_signed_t) atomic_predec(futex) < 0) 71 71 return __SYSCALL1(SYS_FUTEX_SLEEP, (sysarg_t) &futex->count); 72 72 … … 82 82 int futex_up(futex_t *futex) 83 83 { 84 if ( atomic_postinc(futex) < 0)84 if ((atomic_signed_t) atomic_postinc(futex) < 0) 85 85 return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &futex->count); 86 86 -
uspace/lib/libc/include/atomicdflt.h
rbc9da2a r228666c 37 37 38 38 #ifndef LIBC_ARCH_ATOMIC_H_ 39 #error This file cannot be included directly, include atomic.h instead.39 #error This file cannot be included directly, include atomic.h instead. 40 40 #endif 41 41 42 #include <stdint.h> 42 43 #include <bool.h> 43 44 44 45 typedef struct atomic { 45 volatile longcount;46 volatile atomic_count_t count; 46 47 } atomic_t; 47 48 48 static inline void atomic_set(atomic_t *val, longi)49 static inline void atomic_set(atomic_t *val, atomic_count_t i) 49 50 { 50 51 val->count = i; 51 52 } 52 53 53 static inline longatomic_get(atomic_t *val)54 static inline atomic_count_t atomic_get(atomic_t *val) 54 55 { 55 56 return val->count; 56 57 } 57 58 58 59 #ifndef CAS 59 static inline bool cas(atomic_t *val, long ov, longnv)60 static inline bool cas(atomic_t *val, atomic_count_t ov, atomic_count_t nv) 60 61 { 61 62 return __sync_bool_compare_and_swap(&val->count, ov, nv);
Note:
See TracChangeset
for help on using the changeset viewer.