views:

84

answers:

2

Assume this code:

  static inline void inc(int64_t* atomic)
  {
    __asm__ __volatile__
    (
      "lock incq %0\n"
        : "=m" (*atomic)
        : "m" (*atomic)
    );
  }

The Clang compiler doesn't support the lock prefix (yet?). What shall I do now?

+2  A: 

Why not use the built-ins...?

static inlint void inc(int64_t* atomic) {
   __sync_add_and_fetch_8(atomic, 1);
}
KennyTM
looks good. I'll try and if it works I'll accept :)
Polybos
+2  A: 

The integrated assembler doesn't understand prefixes which aren't separate statements yet. As a workaround, you can also just add a ';' after "lock". But as the other comment notes, you are better off using built-ins whenever possible.

Daniel Dunbar