// RuntimeForStatic base library | C+- (SysRoutine) | Author: Sergei Y.Kitáev
#include "Precompiled.h"
#include "SharedIncludes.h"
namespace RuntimeForStatic {
//==================================================================================================

int $Interlocked::Read($A, int volatile* pSource )
{
   return $interlocked::Read($ci, pSource );
}
int $Interlocked::Write($A, int volatile* pTarget, int value ) $ret_target
{
   Exchange($ci, pTarget, value ); return value;
}

int $Interlocked::Exchange($A, int volatile* pLocation, int value ) $ret_previous
{
   return $interlocked::Exchange($ci, pLocation, value );
}
int $Interlocked::CompareExchange($A, int volatile* pLocation,
                                      int exchange, int comparand ) $ret_initial
{
   return $interlocked::CompareExchange($ci, pLocation, exchange, comparand );
}

//==================================================================================================

DWORD $Interlocked::Read($A, DWORD volatile* pSource )
{
   return $interlocked::Read($ci, pSource );
}
DWORD $Interlocked::Write($A, DWORD volatile* pTarget, DWORD value ) $ret_target
{
   Exchange($ci, pTarget, value ); return value;
}

DWORD $Interlocked::Exchange($A, DWORD volatile* pLocation, DWORD value ) $ret_previous
{
   return $interlocked::Exchange($ci, pLocation, value );
}
DWORD $Interlocked::CompareExchange($A, DWORD volatile* pLocation,
                                        DWORD exchange, DWORD comparand ) $ret_initial
{
   return $interlocked::CompareExchange($ci, pLocation, exchange, comparand );
}

//==================================================================================================

PVOID $Interlocked::ReadPointer($A, PVOID volatile* pPointer )
{
   return $interlocked::ReadPointer($ci, pPointer );
}
PVOID $Interlocked::WritePointer($A, PVOID volatile* pTargetPtr, PVOID pointerValue ) $ret_target
{
   return $interlocked::WritePointer($ci, pTargetPtr, pointerValue );
}

PVOID $Interlocked::ExchangePointer($A, PVOID volatile* pPointer,
                                        PVOID pointerValue ) $ret_previous
{
   return $interlocked::ExchangePointer($ci, pPointer, pointerValue );
}
PVOID $Interlocked::CompareExchangePointer($A, PVOID volatile* pPointer,
                                               PVOID exchangePtr, PVOID comparandPtr ) $ret_initial
{
   return $interlocked::CompareExchangePointer($ci, pPointer, exchangePtr, comparandPtr );
}

PVOID $Interlocked::ResetPointer($A, PVOID volatile* pPointer ) $ret_previous
{
   return ExchangePointer($ci, pPointer, nullptr );
}

//==================================================================================================

bool $Interlocked::GetAsBool($A, DWORD volatile* pSource )
{
   return $BOOL( Read($ci, pSource ) );
}

bool $Interlocked::SetAsBool($A, DWORD volatile* pTarget ) $imaginary_param("value",true)
                                                           $ret_target
{
   return SetAsBool($ci, pTarget, true );
}
bool $Interlocked::SetAsBool($A, DWORD volatile* pTarget, bool value ) $ret_target
{
   return $BOOL( Write($ci, pTarget, value ) );
}

bool $Interlocked::ResetAsBool($A, DWORD volatile* pTarget ) $ret_target
{
   return SetAsBool($ci, pTarget, false );
}

bool $Interlocked::ExchangeAsBool($A, DWORD volatile* pLocation, bool value ) $ret_previous
{
   return $BOOL( Exchange($ci, pLocation, $Ops::DWordFromBool( value )) );
}
bool $Interlocked::CompareExchangeAsBool($A, DWORD volatile* pLocation,
                                             bool exchange, bool comparand ) $ret_initial
{
   return $BOOL( CompareExchange($ci, pLocation,
      $Ops::DWordFromBool( exchange ),
      $Ops::DWordFromBool( comparand ) ));
}

//==================================================================================================
} // RuntimeForStatic
