为什么GCC原子内置函数需要附加的“通用”版本?

问题描述 投票:5回答:1

根据https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html,有:

type __atomic_load_n (type *ptr, int memorder)

和(“通用”):

void __atomic_load (type *ptr, type *ret, int memorder)

然后

void __atomic_store_n (type *ptr, type val, int memorder)

和(“通用”)]

void __atomic_store (type *ptr, type *val, int memorder)

后一种版本有什么通用性(前一种版本不是通用的,为什么需要它们?

c gcc intrinsics stdatomic
1个回答
3
投票

答案是正确的section 6.55中的GCC手册,其中说:

'__ atomic'内置函数可以与长度为1、2、4或8个字节的任何整数标量或指针类型一起使用。如果体系结构支持“ __int128”(请参见__int128),则也允许使用16个字节的整数类型。

四个非算术函数(装入,存储,交换和compare_exchange)也都具有通用版本。此通用版本适用于任何数据类型。如果特定的数据类型大小使它成为可能,它将使用无锁内置函数。否则,将在运行时解决外部呼叫。此外部调用的格式相同,但添加了“ size_t”参数作为第一个参数,该参数指示了所指向对象的大小。所有对象的大小必须相同。

© www.soinside.com 2019 - 2024. All rights reserved.