⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atomicint.h

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 H
📖 第 1 页 / 共 2 页
字号:
{    return Uint32(_rep);}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::set(Uint32 n){    _rep = LONG(n);}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::inc(){    InterlockedIncrement(&_rep);}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::dec(){    InterlockedDecrement(&_rep);}PEGASUS_TEMPLATE_SPECIALIZATIONinline bool AtomicIntTemplate<AtomicType>::decAndTestIfZero(){    return InterlockedDecrement(&_rep) == 0;}typedef AtomicIntTemplate<AtomicType> AtomicInt;PEGASUS_NAMESPACE_END#endif /* PEGASUS_PLATFORM_WIN32_IX86_MSVC *///==============================================================================//// PEGASUS_PLATFORM_ZOS_ZSERIES_IBM////==============================================================================#if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)# define PEGASUS_ATOMIC_INT_DEFINEDPEGASUS_NAMESPACE_BEGINstruct AtomicType{    cs_t n;};PEGASUS_TEMPLATE_SPECIALIZATIONinline AtomicIntTemplate<AtomicType>::AtomicIntTemplate(Uint32 n){    _rep.n = (cs_t)n;}PEGASUS_TEMPLATE_SPECIALIZATIONinline AtomicIntTemplate<AtomicType>::~AtomicIntTemplate(){}PEGASUS_TEMPLATE_SPECIALIZATIONinline Uint32 AtomicIntTemplate<AtomicType>::get() const{    return (Uint32)_rep.n;}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::set(Uint32 n){    _rep.n = (cs_t)n;}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::inc(){    Uint32 x = (Uint32)_rep.n;    Uint32 old = x;    x++;    while ( cs( (cs_t*)&old, &(_rep.n), (cs_t)x) )    {       x = (Uint32)_rep.n;       old = x;       x++;    }}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::dec(){    Uint32 x = (Uint32)_rep.n;    Uint32 old = x;    x--;    while ( cs( (cs_t*)&old, &(_rep.n), (cs_t) x) )    {       x = (Uint32) _rep.n;       old = x;       x--;    }}PEGASUS_TEMPLATE_SPECIALIZATIONinline bool AtomicIntTemplate<AtomicType>::decAndTestIfZero(){    Uint32 x = (Uint32)_rep.n;    Uint32 old = x;    x--;    while ( cs( (cs_t*)&old, &(_rep.n), (cs_t) x) )    {       x = (Uint32) _rep.n;       old = x;       x--;    }    return x==0;}typedef AtomicIntTemplate<AtomicType> AtomicInt;PEGASUS_NAMESPACE_END#endif /* PEGASUS_PLATFORM_ZOS_ZSERIES_IBM *///==============================================================================//// PEGASUS_PLATFORM_HPUX_IA64_ACC////==============================================================================#if defined (PEGASUS_PLATFORM_HPUX_IA64_ACC)# define PEGASUS_ATOMIC_INT_DEFINED#include <machine/sys/inline.h>PEGASUS_NAMESPACE_BEGINstruct AtomicType{    volatile Uint32 n;};PEGASUS_TEMPLATE_SPECIALIZATIONinline AtomicIntTemplate<AtomicType>::AtomicIntTemplate(Uint32 n){    _rep.n = n;}PEGASUS_TEMPLATE_SPECIALIZATIONinline AtomicIntTemplate<AtomicType>::~AtomicIntTemplate(){    // Nothing to do!}PEGASUS_TEMPLATE_SPECIALIZATIONinline Uint32 AtomicIntTemplate<AtomicType>::get() const{    return _rep.n;}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::set(Uint32 n){    _rep.n = n;}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::inc(){    _Asm_fetchadd(        (_Asm_fasz)_FASZ_W,        (_Asm_sem)_SEM_ACQ,        (volatile Uint32*)&_rep.n,        (int)1,        (_Asm_ldhint)_LDHINT_NONE);}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::dec(){    _Asm_fetchadd(        (_Asm_fasz)_FASZ_W,        (_Asm_sem)_SEM_ACQ,        (volatile Uint32*)&_rep.n,        (int)-1,        (_Asm_ldhint)_LDHINT_NONE);}PEGASUS_TEMPLATE_SPECIALIZATIONinline bool AtomicIntTemplate<AtomicType>::decAndTestIfZero(){    Uint32 x = _Asm_fetchadd(        (_Asm_fasz)_FASZ_W,        (_Asm_sem)_SEM_ACQ,        (volatile Uint32*)&_rep.n,        (int)-1,        (_Asm_ldhint)_LDHINT_NONE);    return x == 1;}typedef AtomicIntTemplate<AtomicType> AtomicInt;PEGASUS_NAMESPACE_END#endif /* PEGASUS_PLATFORM_HPUX_IA64_ACC *///==============================================================================//// PEGASUS_PLATFORM_LINUX_XSCALE_GNU////==============================================================================#if defined (PEGASUS_PLATFORM_LINUX_XSCALE_GNU)# define PEGASUS_ATOMIC_INT_DEFINEDPEGASUS_NAMESPACE_BEGINinline void AtomicIntDisableIRQs(unsigned long& flags){    unsigned long temp;    unsigned long x;    asm volatile(        "mrs %0, cpsr\n"        "orr %1, %0, #128\n"        "msr cpsr_c, %1\n"        : "=r" (x), "=r" (temp)        :        : "memory");    flags = x;}inline void AtomicIntEnableIRQs(unsigned long x){    unsigned long temp;    asm volatile(        "mrs %0, cpsr\n"        "orr %1, %0, #128\n"        "msr cpsr_c, %1\n"        : "=r" (x), "=r" (temp)        :        : "memory");}struct AtomicType{    volatile Uint32 n;};PEGASUS_TEMPLATE_SPECIALIZATIONinline AtomicIntTemplate<AtomicType>::AtomicIntTemplate(Uint32 n){    _rep.n = n;}PEGASUS_TEMPLATE_SPECIALIZATIONinline AtomicIntTemplate<AtomicType>::~AtomicIntTemplate(){}PEGASUS_TEMPLATE_SPECIALIZATIONinline Uint32 AtomicIntTemplate<AtomicType>::get() const{    return _rep.n;}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::set(Uint32 n){    _rep.n = n;}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::inc(){    unsigned long flags;    AtomicIntDisableIRQs(flags);    _rep.n++;    AtomicIntEnableIRQs(flags);}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::dec(){    unsigned long flags;    AtomicIntDisableIRQs(flags);    _rep.n--;    AtomicIntEnableIRQs(flags);}PEGASUS_TEMPLATE_SPECIALIZATIONinline bool AtomicIntTemplate<AtomicType>::decAndTestIfZero(){    Uint32 tmp;    unsigned long flags;    AtomicIntDisableIRQs(flags);    tmp = --_rep.n;    AtomicIntEnableIRQs(flags);    return tmp == 0;}typedef AtomicIntTemplate<AtomicType> AtomicInt;PEGASUS_NAMESPACE_END#endif /* PEGASUS_PLATFORM_LINUX_XSCALE_GNU *///==============================================================================//// PEGASUS_PLATFORM_VMS_ALPHA_DECCXX// PEGASUS_PLATFORM_VMS_IA64_DECCXX////==============================================================================#if defined (PEGASUS_PLATFORM_VMS_ALPHA_DECCXX) || \    defined (PEGASUS_PLATFORM_VMS_IA64_DECCXX)# define PEGASUS_ATOMIC_INT_DEFINED# include <sys/machine/builtins.h>PEGASUS_NAMESPACE_BEGINstruct AtomicType{    volatile int n;};PEGASUS_TEMPLATE_SPECIALIZATIONinline AtomicIntTemplate<AtomicType>::AtomicIntTemplate(Uint32 n){    _rep.n = n;}PEGASUS_TEMPLATE_SPECIALIZATIONinline AtomicIntTemplate<AtomicType>::~AtomicIntTemplate(){}PEGASUS_TEMPLATE_SPECIALIZATIONinline Uint32 AtomicIntTemplate<AtomicType>::get() const{    return _rep.n;}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::set(Uint32 n){    _rep.n = n;}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::inc(){    __ATOMIC_INCREMENT_LONG(&_rep.n);}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::dec(){    __ATOMIC_DECREMENT_LONG(&_rep.n);}PEGASUS_TEMPLATE_SPECIALIZATIONinline bool AtomicIntTemplate<AtomicType>::decAndTestIfZero(){    return __ATOMIC_DECREMENT_LONG(&_rep.n) == 1;}typedef AtomicIntTemplate<AtomicType> AtomicInt;PEGASUS_NAMESPACE_END#endif /* _Pegasus_Common_AtomicInt_VMS_h *///==============================================================================//// Generic Implementation////==============================================================================#if !defined(PEGASUS_ATOMIC_INT_DEFINED)# define PEGASUS_ATOMIC_INT_DEFINED# include <Pegasus/Common/SpinLock.h>PEGASUS_NAMESPACE_BEGIN// Represents the atomic type counter.struct AtomicType{    Uint32 n;};PEGASUS_TEMPLATE_SPECIALIZATIONinline AtomicIntTemplate<AtomicType>::AtomicIntTemplate(Uint32 n){    _rep.n = n;    if (spinLockPoolInitialized == 0)        SpinLockCreatePool();}PEGASUS_TEMPLATE_SPECIALIZATIONinline AtomicIntTemplate<AtomicType>::~AtomicIntTemplate(){    // Nothing to do.}PEGASUS_TEMPLATE_SPECIALIZATIONinline Uint32 AtomicIntTemplate<AtomicType>::get() const{    Uint32 tmp;    size_t i = SpinLockIndex(&_rep);    SpinLockLock(spinLockPool[i]);    tmp = _rep.n;    SpinLockUnlock(spinLockPool[i]);    return tmp;}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::set(Uint32 n){    size_t i = SpinLockIndex(&_rep);    SpinLockLock(spinLockPool[i]);    _rep.n = n;    SpinLockUnlock(spinLockPool[i]);}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::inc(){    size_t i = SpinLockIndex(&_rep);    SpinLockLock(spinLockPool[i]);    _rep.n++;    SpinLockUnlock(spinLockPool[i]);}PEGASUS_TEMPLATE_SPECIALIZATIONinline void AtomicIntTemplate<AtomicType>::dec(){    size_t i = SpinLockIndex(&_rep);    SpinLockLock(spinLockPool[i]);    _rep.n--;    SpinLockUnlock(spinLockPool[i]);}PEGASUS_TEMPLATE_SPECIALIZATIONinline bool AtomicIntTemplate<AtomicType>::decAndTestIfZero(){    Uint32 tmp;    size_t i = SpinLockIndex(&_rep);    SpinLockLock(spinLockPool[i]);    tmp = --_rep.n;    SpinLockUnlock(spinLockPool[i]);    return tmp == 0;}typedef AtomicIntTemplate<AtomicType> AtomicInt;PEGASUS_NAMESPACE_END#endif /* !PEGASUS_ATOMIC_INT_DEFINED */#endif /* Pegasus_AtomicInt_h */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -