Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Base - API - Platform [Atomic].i_inc
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/* == Common ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Public Functions                                                                                                                                                      */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- Atomic ------------------------------------------------------------------------------------------------------------------------------------------------------------ */


/* ---- F(tgAM, _WRITE_FENCE) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID F(tgAM, _WRITE_FENCE)( TgVOID )
{
}


/* ---- F(tgAM, _READ_FENCE) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID F(tgAM, _READ_FENCE)( TgVOID )
{
}


/* ---- F(tgAM, _FULL_FENCE) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID F(tgAM, _FULL_FENCE)( TgVOID )
{
}


/* ---- Atomic Pointer Functions ---------------------------------------------------------------------------------------------------------------------------------------- */

/* ---- F(tgAMPT, _READ) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE P_TgVOID F(tgAMPT, _READ)( volatile TgATOMIC_PVOID *piTarget )
{
    return (*piTarget);
}


/* ---- F(tgAMPT, _WRITE) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID F(tgAMPT, _WRITE)( volatile TgATOMIC_PVOID *piTarget, PC_TgVOID pVal )
{
    *(volatile TgUINTPTR*)piTarget = (TgUINTPTR)pVal;
}


/* ---- F(tgAMPT, _XCHG) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE P_TgVOID F(tgAMPT, _XCHG)( volatile TgATOMIC_PVOID *piTarget, PC_TgVOID pVal )
{
    TgUINTPTR uiReturn = *(volatile TgUINTPTR*)piTarget;
    *(volatile TgUINTPTR*)piTarget = (TgUINTPTR)pVal;
    return ((P_TgVOID)uiReturn);
}


/* ---- F(tgAMPT, _XCMP) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE P_TgVOID F(tgAMPT, _XCMP)( volatile TgATOMIC_PVOID *piTarget, PC_TgVOID pVal, PC_TgVOID pCmp )
{
    TgUINTPTR uiReturn = *(volatile TgUINTPTR*)piTarget;
    if (uiReturn == (TgUINTPTR)pCmp)
        *(volatile TgUINTPTR*)piTarget = (TgUINTPTR)pVal;
    return ((P_TgVOID)uiReturn);
}


#if TgCOMPILE_64BIT_POINTER

/* ---- F(tgAMXX, _READ) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _READ)( volatile TgATOMIC_UINTXX *puiTarget )
{
    return (*puiTarget);
}


/* ---- F(tgAMXX, _WRITE) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID F(tgAMXX, _WRITE)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    F(tgAM64, _WRITE)( (volatile TgATOMIC_SINT64*)puiTarget, (C_TgSINT64)uiVal );
}


/* ---- F(tgAMXX, _XADD) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _XADD)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    return ((TgSIZE)F(tgAM64, _XADD)( (volatile TgATOMIC_SINT64*)puiTarget, (C_TgSINT64)uiVal ));
}


/* ---- F(tgAMXX, _XSUB) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _XSUB)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    return ((TgSIZE)F(tgAM64, _XSUB)( (volatile TgATOMIC_SINT64*)puiTarget, (C_TgSINT64)uiVal ));
}


/* ---- F(tgAMXX, _AND) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _AND)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    return ((TgSIZE)F(tgAM64, _AND)( (volatile TgATOMIC_SINT64*)puiTarget, (C_TgSINT64)uiVal ));
}


/* ---- F(tgAMXX, _OR) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _OR)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    return ((TgSIZE)F(tgAM64, _OR)( (volatile TgATOMIC_SINT64*)puiTarget, (C_TgSINT64)uiVal ));
}


/* ---- F(tgAMXX, _XOR) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _XOR)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    return ((TgSIZE)F(tgAM64, _XOR)( (volatile TgATOMIC_SINT64*)puiTarget, (C_TgSINT64)uiVal ));
}


/* ---- F(tgAMXX, _INC) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _INC)( volatile TgATOMIC_UINTXX *puiTarget)
{
    return ((TgSIZE)F(tgAM64, _INC)( (volatile TgATOMIC_SINT64*)puiTarget ));
}


/* ---- F(tgAMXX, _DEC) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _DEC)( volatile TgATOMIC_UINTXX *puiTarget)
{
    return ((TgSIZE)F(tgAM64, _DEC)( (volatile TgATOMIC_SINT64*)puiTarget ));
}


/* ---- F(tgAMXX, _XCHG) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _XCHG)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    return ((TgSIZE)F(tgAM64, _XCHG)( (volatile TgATOMIC_SINT64*)puiTarget, (C_TgSINT64)uiVal ));
}


/* ---- F(tgAMXX, _XCMP) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _XCMP)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal, C_TgUINTXX uiCmp )
{
    return ((TgSIZE)F(tgAM64, _XCMP)( (volatile TgATOMIC_SINT64*)puiTarget, (C_TgSINT64)uiVal, (C_TgSINT64)uiCmp ));
}


/* ---- F(tgAMXX, _XCMP2) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL F(tgAMXX, _XCMP2)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiHigh, C_TgUINTXX uiLow, PC_TgUINTXX puiCmpResult )
{
    if ((puiTarget[0] == puiCmpResult[0]) && (puiTarget[1] == puiCmpResult[1]))
    {
        puiTarget[0] = uiLow;
        puiTarget[1] = uiHigh;
        return (TgTRUE);
    }
    puiCmpResult[0] = puiTarget[0];
    puiCmpResult[1] = puiTarget[1];
    return (TgFALSE);
}


#elif TgCOMPILE_32BIT_POINTER

/* ---- F(tgAMXX, _READ) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _READ)( volatile TgATOMIC_UINTXX *puiTarget )
{
    return ((TgSIZE)*puiTarget);
}


/* ---- F(tgAMXX, _WRITE) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID F(tgAMXX, _WRITE)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    F(tgAM32, _WRITE)( (volatile TgATOMIC_SINT32*)puiTarget, (C_TgSINT32)uiVal );
}


/* ---- F(tgAMXX, _XADD) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _XADD)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    return ((TgSIZE)F(tgAM32, _XADD)( (volatile TgATOMIC_SINT32*)puiTarget, (C_TgSINT32)uiVal ));
}


/* ---- F(tgAMXX, _XSUB) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _XSUB)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    return ((TgSIZE)F(tgAM32, _XSUB)( (volatile TgATOMIC_SINT32*)puiTarget, (C_TgSINT32)uiVal ));
}


/* ---- F(tgAMXX, _AND) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _AND)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    return ((TgSIZE)F(tgAM32, _AND)( (volatile TgATOMIC_SINT32*)puiTarget, (C_TgSINT32)uiVal ));
}


/* ---- F(tgAMXX, _OR) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _OR)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    return ((TgSIZE)F(tgAM32, _OR)( (volatile TgATOMIC_SINT32*)puiTarget, (C_TgSINT32)uiVal ));
}


/* ---- F(tgAMXX, _XOR) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _XOR)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    return ((TgSIZE)F(tgAM32, _XOR)( (volatile TgATOMIC_SINT32*)puiTarget, (C_TgSINT32)uiVal ));
}


/* ---- F(tgAMXX, _INC) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _INC)( volatile TgATOMIC_UINTXX *puiTarget)
{
    return ((TgSIZE)F(tgAM32, _INC)( (volatile TgATOMIC_SINT32*)puiTarget ));
}


/* ---- F(tgAMXX, _DEC) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _DEC)( volatile TgATOMIC_UINTXX *puiTarget)
{
    return ((TgSIZE)F(tgAM32, _DEC)( (volatile TgATOMIC_SINT32*)puiTarget ));
}


/* ---- F(tgAMXX, _XCHG) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _XCHG)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal )
{
    return ((TgSIZE)F(tgAM32, _XCHG)((volatile TgATOMIC_SINT32*)puiTarget, (C_TgSINT32)uiVal ));
}


/* ---- F(tgAMXX, _XCMP) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgUINTXX F(tgAMXX, _XCMP)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiVal, C_TgUINTXX uiCmp )
{
    return ((TgSIZE)F(tgAM32, _XCMP)( (volatile TgATOMIC_SINT64*)puiTarget, (C_TgSINT64)uiVal, (C_TgSINT64)uiCmp ));
}


/* ---- F(tgAMXX, _XCMP2) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL F(tgAMXX, _XCMP2)( volatile TgATOMIC_UINTXX *puiTarget, C_TgUINTXX uiHigh, C_TgUINTXX uiLow, PC_TgUINTXX puiCmpResult )
{
    if ((puiTarget[0] == puiCmpResult[0]) && (puiTarget[1] == puiCmpResult[1]))
    {
        puiTarget[0] = uiLow;
        puiTarget[1] = uiHigh;
        return (TgTRUE);
    }
    puiCmpResult[0] = puiTarget[0];
    puiCmpResult[1] = puiTarget[1];
    return (TgFALSE);
}

#else
    #error Unsupported pointer size
#endif




/* ---- Atomic 16bit Functions ------------------------------------------------------------------------------------------------------------------------------------------ */
#if TgCOMPILE_16BIT_ATOMIC

/* ---- F(tgAM16, _READ) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT16 F(tgAM16, _READ)( volatile TgATOMIC_SINT16 *piTarget )
{
    return (*piTarget);
}


/* ---- F(tgAM16, _WRITE) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT16 F(tgAM16, _WRITE)( volatile TgATOMIC_SINT16 *piTarget, C_TgSINT16 iVal )
{
    *piTarget = iVal;
}


/* ---- F(tgAM16, _AND) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT16 F(tgAM16, _AND)( volatile TgATOMIC_SINT16 *piTarget, C_TgSINT16 iVal )
{
    TgATOMIC_SINT16 iReturn = *piTarget;
    *piTarget = *piTarget & iVal;
    return (iReturn);
}


/* ---- F(tgAM16, _OR) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT16 F(tgAM16, _OR)( volatile TgATOMIC_SINT16 *piTarget, C_TgSINT16 iVal )
{
    TgATOMIC_SINT16 iReturn = *piTarget;
    *piTarget = *piTarget | iVal;
    return (iReturn);
}


/* ---- F(tgAM16, _XOR) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT16 F(tgAM16, _XOR)( volatile TgATOMIC_SINT16 *piTarget, C_TgSINT16 iVal )
{
    TgATOMIC_SINT16 iReturn = *piTarget;
    *piTarget = *piTarget ^ iVal;
    return (iReturn);
}


/* ---- F(tgAM16, _INC) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT16 F(tgAM16, _INC)( volatile TgATOMIC_SINT16 *piTarget )
{
    TgATOMIC_SINT16 iReturn = *piTarget;
    *piTarget = *piTarget + 1;
    return (*piTarget);
}


/* ---- F(tgAM16, _DEC) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT16 F(tgAM16, _DEC)( volatile TgATOMIC_SINT16 *piTarget )
{
    TgATOMIC_SINT16 iReturn = *piTarget;
    *piTarget = *piTarget - 1;
    return (*piTarget);
}

/*# TgCOMPILE_16BIT_ATOMIC */
#endif




/* ---- Atomic 32bit Functions ------------------------------------------------------------------------------------------------------------------------------------------ */

/* ---- F(tgAM32, _READ) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 F(tgAM32, _READ)( volatile TgATOMIC_SINT32 *piTarget )
{
    return (*piTarget);
}


/* ---- F(tgAM32, _WRITE) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID F(tgAM32, _WRITE)( volatile TgATOMIC_SINT32 *piTarget, C_TgSINT32 iVal )
{
    *piTarget = iVal;
}


/* ---- F(tgAM32, _XADD) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 F(tgAM32, _XADD)( volatile TgATOMIC_SINT32 *piTarget, C_TgSINT32 iVal )
{
    TgATOMIC_SINT32 iReturn = *piTarget;
    *piTarget = *piTarget + iVal;
    return (iReturn);
}


/* ---- F(tgAM32, _XSUB) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 F(tgAM32, _XSUB)( volatile TgATOMIC_SINT32 *piTarget, C_TgSINT32 iVal )
{
    TgATOMIC_SINT32 iReturn = *piTarget;
    *piTarget = *piTarget - iVal;
    return (iReturn);
}


/* ---- F(tgAM32, _AND) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 F(tgAM32, _AND)( volatile TgATOMIC_SINT32 *piTarget, C_TgSINT32 iVal )
{
    TgATOMIC_SINT32 iReturn = *piTarget;
    *piTarget = *piTarget & iVal;
    return (iReturn);
}


/* ---- F(tgAM32, _OR) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 F(tgAM32, _OR)( volatile TgATOMIC_SINT32 *piTarget, C_TgSINT32 iVal )
{
    TgATOMIC_SINT32 iReturn = *piTarget;
    *piTarget = *piTarget | iVal;
    return (iReturn);
}


/* ---- F(tgAM32, _XOR) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 F(tgAM32, _XOR)( volatile TgATOMIC_SINT32 *piTarget, C_TgSINT32 iVal )
{
    TgATOMIC_SINT32 iReturn = *piTarget;
    *piTarget = *piTarget ^ iVal;
    return (iReturn);
}


/* ---- F(tgAM32, _INC) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 F(tgAM32, _INC)( volatile TgATOMIC_SINT32 *piTarget )
{
    *piTarget = *piTarget + 1;
    return (*piTarget);
}


/* ---- F(tgAM32, _DEC) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 F(tgAM32, _DEC)( volatile TgATOMIC_SINT32 *piTarget )
{
    *piTarget = *piTarget - 1;
    return (*piTarget);
}


/* ---- F(tgAM32, _XCHG) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 F(tgAM32, _XCHG)( volatile TgATOMIC_SINT32 *piTarget, C_TgSINT32 iVal )
{
    TgATOMIC_SINT32 iReturn = *piTarget;
    *piTarget = iVal;
    return (iReturn);
}


/* ---- F(tgAM32, _XCMP) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 F(tgAM32, _XCMP)( volatile TgATOMIC_SINT32 *piTarget, C_TgSINT32 iVal, C_TgSINT32 iCmp )
{
    TgATOMIC_SINT32 iReturn = *piTarget;
    if (iReturn == iCmp)
        *piTarget = iVal;
    return (iReturn);
}


/* ---- F(tgAM64, _XCMP) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT64 F(tgAM64, _XCMP)( volatile TgATOMIC_SINT64 *piTarget, C_TgSINT64 iVal, C_TgSINT64 iCmp )
{
    TgATOMIC_SINT64 iReturn = *piTarget;
    if (iReturn == iCmp)
        *piTarget = iVal;
    return (iReturn);
}




/* ---- Atomic 64bit Functions ------------------------------------------------------------------------------------------------------------------------------------------ */
#if TgCOMPILE_64BIT_ATOMIC

/* ---- F(tgAM64, _READ) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT64 F(tgAM64, _READ)( volatile TgATOMIC_SINT64 *piTarget )
{
    return (*piTarget);
}


/* ---- F(tgAM64, _WRITE) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID F(tgAM64, _WRITE)( volatile TgATOMIC_SINT64 *piTarget, C_TgSINT64 iVal )
{
    *piTarget = iVal;
}


/* ---- F(tgAM64, _XADD) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT64 F(tgAM64, _XADD)( volatile TgATOMIC_SINT64 *piTarget, C_TgSINT64 iVal )
{
    TgATOMIC_SINT64 iReturn = *piTarget;
    *piTarget = *piTarget + iVal;
    return (iReturn);
}


/* ---- F(tgAM64, _XSUB) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT64 F(tgAM64, _XSUB)( volatile TgATOMIC_SINT64 *piTarget, C_TgSINT64 iVal )
{
    TgATOMIC_SINT64 iReturn = *piTarget;
    *piTarget = *piTarget - iVal;
    return (iReturn);
}


/* ---- F(tgAM64, _AND) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT64 F(tgAM64, _AND)( volatile TgATOMIC_SINT64 *piTarget, C_TgSINT64 iVal )
{
    TgATOMIC_SINT64 iReturn = *piTarget;
    *piTarget = *piTarget & iVal;
    return (iReturn);
}


/* ---- F(tgAM64, _OR) -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT64 F(tgAM64, _OR)( volatile TgATOMIC_SINT64 *piTarget, C_TgSINT64 iVal )
{
    TgATOMIC_SINT64 iReturn = *piTarget;
    *piTarget = *piTarget | iVal;
    return (iReturn);
}


/* ---- F(tgAM64, _XOR) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT64 F(tgAM64, _XOR)( volatile TgATOMIC_SINT64 *piTarget, C_TgSINT64 iVal )
{
    TgATOMIC_SINT64 iReturn = *piTarget;
    *piTarget = *piTarget ^ iVal;
    return (iReturn);
}


/* ---- F(tgAM64, _INC) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT64 F(tgAM64, _INC)( volatile TgATOMIC_SINT64 *piTarget )
{
    *piTarget = *piTarget + 1;
    return (*piTarget);
}


/* ---- F(tgAM64, _DEC) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT64 F(tgAM64, _DEC)( volatile TgATOMIC_SINT64 *piTarget )
{
    *piTarget = *piTarget - 1;
    return (*piTarget);
}


/* ---- F(tgAM64, _XCHG) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT64 F(tgAM64, _XCHG)( volatile TgATOMIC_SINT64 *piTarget, C_TgSINT64 iVal )
{
    TgATOMIC_SINT64 iReturn = *piTarget;
    *piTarget = iVal;
    return (iReturn);
}

/* ---- F(tgAM64, _XCMP2) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL F(tgAM64, _XCMP2)( volatile TgATOMIC_SINT64 *piTarget, C_TgSINT64 iHigh, C_TgSINT64 iLow, P_TgSINT64 piCmpResult )
{
    if ((piTarget[0] == piCmpResult[0]) && (piTarget[1] == piCmpResult[1]))
    {
        piTarget[0] = iLow;
        piTarget[1] = iHigh;
        return (TgTRUE);
    }
    piCmpResult[0] = piTarget[0];
    piCmpResult[1] = piTarget[1];
    return (TgFALSE);
}

/*# TgCOMPILE_64BIT_ATOMIC */
#endif