atomic笔记

inline void ice_atomic_set(ice_atomic_t* v, int i)

{

    v->counter = i;

}

 

/*

 * ice_atomic_inc - increment ice_atomic variable

 * @v: pointer of type ice_atomic_t

 * 

 * Atomically increments @v by 1. Note that the guaranteed useful

 * range of an ice_atomic_t is only 24 bits.

 *

 * Inlined because this operation is performance critical.

 */

inline void ice_atomic_inc(ice_atomic_t *v)

{

    __asm__ __volatile__(

        "lock ; incl %0"

        :"=m" (v->counter)

        :"m" (v->counter));

}

 

/**

 * ice_atomic_dec_and_test - decrement and test

 * @v: pointer of type ice_atomic_t

 * 

 * Atomically decrements @v by 1 and returns true if the result is 0,

 * or false for all other cases. Note that the guaranteed useful

 * range of an ice_atomic_t is only 24 bits.

 *

 * Inlined because this operation is performance critical.

 */

inline int ice_atomic_dec_and_test(ice_atomic_t *v)

{

    unsigned char c;

    __asm__ __volatile__(

        "lock ; decl %0; sete %1"

        :"=m" (v->counter), "=qm" (c)

        :"m" (v->counter) : "memory");

    return c != 0;

}

 

/**

 * ice_atomic_exchange_add - same as InterlockedExchangeAdd. This

 * didn't come from atomic.h (the code was derived from similar code

 * in /usr/include/asm/rwsem.h)

 *

 * Inlined because this operation is performance critical.

 */

inline int ice_atomic_exchange_add(int i, ice_atomic_t* v)

{

    int tmp = i;

    __asm__ __volatile__(

        "lock ; xadd %0,(%2)"

        :"+r"(tmp), "=m"(v->counter)

        :"r"(v), "m"(v->counter)

        : "memory");

    return tmp + i;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值