开发者

Clang doesn't support the Lock Prefix. How shall I workaround?

Assume this code:

  static inline void inc(in开发者_如何学Got64_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?


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.


Why not use the built-ins...?

static inlint void inc(int64_t* atomic) {
   __sync_add_and_fetch_8(atomic, 1);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜