Subversion Repositories HelenOS-historic

Rev

Rev 1702 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1702 Rev 1780
Line 47... Line 47...
47
 *
47
 *
48
 * @return Value of the atomic variable as it existed before addition.
48
 * @return Value of the atomic variable as it existed before addition.
49
 */
49
 */
50
static inline long atomic_add(atomic_t *val, int i)
50
static inline long atomic_add(atomic_t *val, int i)
51
{
51
{
52
    __u64 a, b;
52
    uint64_t a, b;
53
    volatile __u64 x = (__u64) &val->count;
53
    volatile uint64_t x = (uint64_t) &val->count;
54
 
54
 
55
    __asm__ volatile (
55
    __asm__ volatile (
56
        "0:\n"
56
        "0:\n"
57
        "ldx %0, %1\n"
57
        "ldx %0, %1\n"
58
        "add %1, %3, %2\n"
58
        "add %1, %3, %2\n"
59
        "casx %0, %1, %2\n"
59
        "casx %0, %1, %2\n"
60
        "cmp %1, %2\n"
60
        "cmp %1, %2\n"
61
        "bne 0b\n"      /* The operation failed and must be attempted again if a != b. */
61
        "bne 0b\n"      /* The operation failed and must be attempted again if a != b. */
62
        "nop\n"
62
        "nop\n"
63
        : "=m" (*((__u64 *)x)), "=r" (a), "=r" (b)
63
        : "=m" (*((uint64_t *)x)), "=r" (a), "=r" (b)
64
        : "r" (i)
64
        : "r" (i)
65
    );
65
    );
66
 
66
 
67
    return a;
67
    return a;
68
}
68
}