分类:
2008-11-05 05:52:16
;;; u32_t atomic_modify(u32_t *addr, u32_t mask, u32_t delta);@File: atomic.h
;;; @param [r3]: addr
;;; @param [r4]: mask
;;; @param [r5]: delta
;;; @return [r3]: the old value
.global atomic_modify
atomic_modify:
lwarx r6,0,r3
andc r7,r6,r4
add r7,r7,r5
stwcx. r7,0,r3
bne+ atomic_modify
mr r3,r6
blr
#ifndef LIBCOMMON_ATOMIC_H
#define LIBCOMMON_ATOMIC_H
unsigned int atomic_modify(unsigned int *addr, unsigned int mask, unsigned int delta);
inline unsigned int atomic_decrement(unsigned int *pval)
{
return atomic_modify(pval, 0, ~(unsigned int)0);
}
inline unsigned int atomic_increment(unsigned int *pval)
{
return atomic_modify(pval, 0, 1);
}
inline unsigned int atomic_read(unsigned int *pval)
{
return atomic_modify(pval, 0, 0);
}
inline unsigned int atomic_write(unsigned int *pval, unsigned int val)
{
return atomic_modify(pval, ~(unsigned int)0, val);
}
#endif