Rev 1864 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1864 | Rev 1888 | ||
---|---|---|---|
Line 47... | Line 47... | ||
47 | * @return Value of the atomic variable as it existed before addition. |
47 | * @return Value of the atomic variable as it existed before addition. |
48 | */ |
48 | */ |
49 | static inline long atomic_add(atomic_t *val, int i) |
49 | static inline long atomic_add(atomic_t *val, int i) |
50 | { |
50 | { |
51 | uint64_t a, b; |
51 | uint64_t a, b; |
52 | volatile uint64_t x = (uint64_t) &val->count; |
- | |
53 | 52 | ||
54 | __asm__ volatile ( |
- | |
55 | "0:\n" |
53 | do { |
56 | "ldx %0, %1\n" |
- | |
57 | "add %1, %3, %2\n" |
54 | volatile uintptr_t x = (uint64_t) &val->count; |
- | 55 | ||
58 | "casx %0, %1, %2\n" |
56 | a = *((uint64_t *) x); |
59 | "cmp %1, %2\n" |
57 | b = a + i; |
60 | "bne 0b\n" /* The operation failed and must be attempted again if a != b. */ |
- | |
61 | "nop\n" |
- | |
62 | : "=m" (*((uint64_t *)x)), "=r" (a), "=r" (b) |
58 | __asm__ volatile ("casx %0, %1, %2\n": "+m" (*((uint64_t *)x)), "+r" (a), "+r" (b)); |
63 | : "r" (i) |
59 | } while (a != b); |
64 | ); |
- | |
65 | 60 | ||
66 | return a; |
61 | return a; |
67 | } |
62 | } |
68 | 63 | ||
69 | static inline long atomic_preinc(atomic_t *val) |
64 | static inline long atomic_preinc(atomic_t *val) |