int linux 原子操作_linux原子操作

linux2.6.18

之后,

删除了

头文件,

编译器提供内建

(

built-in

)

原子操作函数。需要在

gcc

编译选项中指明

CPU

类型。如

gcc

-marth=i686

-o hello hello.c

type

可以是以下类型

:

int

unsigned int

long

unsigned long

long long

unsigned long long

以下函数返回修改之前的值:

type __sync_fetch_and_add (type *ptr, type value);

type __sync_fetch_and_sub (type *ptr, type value);

type __sync_fetch_and_or (type *ptr, type value);

type __sync_fetch_and_and (type *ptr, type value);

type __sync_fetch_and_xor (type *ptr, type value);

type __sync_fetch_and_nand (type *ptr, type value);

以下函数返回修改之后的值:

type __sync_add_and_fetch (type *ptr, type value);

type __sync_sub_and_fetch (type *ptr, type value);

type __sync_or_and_fetch (type *ptr, type value);

type __sync_and_and_fetch (type *ptr, type value);

type __sync_xor_and_fetch (type *ptr, type value);

type __sync_nand_and_fetch (type *ptr, type value);

更多信息:

Built-in functions for atomic memory access

The following builtins are intended to be compatible with those described in the Intel Itanium

Processor-specific Application Binary Interface, section 7.4. As such, they depart from the normal

GCC practice of using the “__builtin_” prefix, and further tha

t they are overloaded such that they

work on multiple types.

The definition given in the Intel documentation allows only for the use of the types int, long, long

long as well as their unsigned counterparts. GCC will allow any integral scalar or pointer type that

is 1, 2, 4 or 8 bytes in length.

Not

all

operations

are

supported

by

all

target

processors.

If

a

particular

operation

cannot

be

implemented on the target processor, a warning will be generated and a call an external function

will

be

generated.

The

external

function

will

carry

the

same

name

as

the

builtin,

with

an

additional suffix `_n' where n is the size of the data type.

In

most

cases,

these

builtins

are

considered

a

full

barrier.

That

is,

no

memory

operand

will

be

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值