开发者

The alternative of __sync_val_compare_and_swap function for old gcc compiler

开发者 https://www.devze.com 2023-04-11 22:22 出处:网络
I have in my project the following method: long compare( long* avar, long comp, long exc ) { return __sync_val_compare_and_swap( avar, comp, exc );

I have in my project the following method:

long compare( long* avar, long comp, long exc )
{
    return __sync_val_compare_and_swap( avar, comp, exc );
}

But if i want to compile my project using gcc of version (older vers开发者_如何转开发ion, 3.4.3 for instance) which doesn't support AtomicBuiltins What is the alternative path of the solution our problem? What kind of the alternative functions( the alternative of __sync_val_compare_and_swap ) or block of functions we can use instead of __sync_val_compare_and_swap?


The only alternative that I would see is that you'd have to implement this through assembler. I think the asm extension of gcc predates the stone age, so any compiler that you might encouter will support this.

Implementing this particular function is not so difficult, and you'd find references easily. You'd have to provide different implementations for each architecture that you care for, though.

0

精彩评论

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

关注公众号