开发者

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

开发者 https://www.devze.com 2023-01-01 06:38 出处:网络
Assume this code: static inline void inc(in开发者_如何学Got64_t* atomic) { __asm__ __volatile__ ( \"lock incq %0\\n\"

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

精彩评论

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