Skip to content
  • parcs's avatar
    Fix the definition of cas() on x86 (#8219) · 84dff710
    parcs authored
    *p is both read and written to by the cmpxchg instruction, and therefore
    should be given the '+' constraint modifier.
    
    (In GCC's extended ASM language, '+' means that the operand is both read
    and written to whereas '=' means that it is only written to.)
    
    Otherwise, the compiler is allowed to rewrite something like
    
    SpinLock lock;
    initSpinLock(&lock);       /* sets lock = 1 */
    ACQUIRE_SPIN_LOCK(&lock);
    
    into
    
    SpinLock lock;
    ACQUIRE_SPIN_LOCK(&lock);
    
    because according to the asm statement, the previous value of 'lock' is
    not important.
    84dff710