platformIntrinsics.visualc.h
Engine/source/platform/platformIntrinsics.visualc.h
Compiler intrinsics for Visual C++.
Public Functions
dAtomicRead(volatile U32 & ref)
Performs an atomic read operation.
bool
dCompareAndSwap(volatile U32 & ref, U32 oldVal, U32 newVal)
bool
dCompareAndSwap(volatile U64 & ref, U64 oldVal, U64 newVal)
dFetchAndAdd(volatile S32 & ref, S32 val)
dFetchAndAdd(volatile U32 & ref, U32 val)
Detailed Description
Compiler intrinsics for Visual C++.
Public Functions
dAtomicRead(volatile U32 & ref)
Performs an atomic read operation.
dCompareAndSwap(volatile U32 & ref, U32 oldVal, U32 newVal)
dCompareAndSwap(volatile U64 & ref, U64 oldVal, U64 newVal)
dFetchAndAdd(volatile S32 & ref, S32 val)
dFetchAndAdd(volatile U32 & ref, U32 val)
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _TORQUE_PLATFORM_PLATFORMINTRINSICS_VISUALC_H_ 25#define _TORQUE_PLATFORM_PLATFORMINTRINSICS_VISUALC_H_ 26 27/// @file 28/// Compiler intrinsics for Visual C++. 29 30#if defined(TORQUE_OS_XENON) 31# include <Xtl.h> 32# define _InterlockedExchangeAdd InterlockedExchangeAdd 33# define _InterlockedExchangeAdd64 InterlockedExchangeAdd64 34#else 35# include <intrin.h> 36#endif 37 38// Fetch-And-Add 39// 40// NOTE: These do not return the pre-add value because 41// not all platforms (damn you OSX) can do that. 42// 43inline void dFetchAndAdd( volatile U32& ref, U32 val ) 44{ 45 _InterlockedExchangeAdd( ( volatile long* ) &ref, val ); 46} 47inline void dFetchAndAdd( volatile S32& ref, S32 val ) 48{ 49 _InterlockedExchangeAdd( ( volatile long* ) &ref, val ); 50} 51 52#if defined(TORQUE_OS_XENON) 53// Not available on x86 54inline void dFetchAndAdd( volatile U64& ref, U64 val ) 55{ 56 _InterlockedExchangeAdd64( ( volatile __int64* ) &ref, val ); 57} 58#endif 59 60// Compare-And-Swap 61 62inline bool dCompareAndSwap( volatile U32& ref, U32 oldVal, U32 newVal ) 63{ 64 return ( _InterlockedCompareExchange( ( volatile long* ) &ref, newVal, oldVal ) == oldVal ); 65} 66inline bool dCompareAndSwap( volatile U64& ref, U64 oldVal, U64 newVal ) 67{ 68 return ( _InterlockedCompareExchange64( ( volatile __int64* ) &ref, newVal, oldVal ) == oldVal ); 69} 70 71/// Performs an atomic read operation. 72inline U32 dAtomicRead( volatile U32 &ref ) 73{ 74 return _InterlockedExchangeAdd( ( volatile long* )&ref, 0 ); 75} 76 77#endif // _TORQUE_PLATFORM_PLATFORMINTRINSICS_VISUALC_H_ 78
