Torque3D Documentation / _generateds / platformIntrinsics.visualc.h

platformIntrinsics.visualc.h

Engine/source/platform/platformIntrinsics.visualc.h

Compiler intrinsics for Visual C++.

More...

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#include <intrin.h>
31
32// Fetch-And-Add
33//
34// NOTE: These do not return the pre-add value because
35// not all platforms (damn you OSX) can do that.
36//
37inline void dFetchAndAdd( volatile U32& ref, U32 val )
38{  
39   _InterlockedExchangeAdd( ( volatile long* ) &ref, val );
40}
41inline void dFetchAndAdd( volatile S32& ref, S32 val )
42{
43   _InterlockedExchangeAdd( ( volatile long* ) &ref, val );
44}
45
46// Compare-And-Swap
47inline bool dCompareAndSwap( volatile U32& ref, U32 oldVal, U32 newVal )
48{
49   return ( _InterlockedCompareExchange( ( volatile long* ) &ref, newVal, oldVal ) == oldVal );
50}
51inline bool dCompareAndSwap( volatile U64& ref, U64 oldVal, U64 newVal )
52{
53   return ( _InterlockedCompareExchange64( ( volatile __int64* ) &ref, newVal, oldVal ) == oldVal );
54}
55
56/// Performs an atomic read operation.
57inline U32 dAtomicRead( volatile U32 &ref )
58{
59   return _InterlockedExchangeAdd( ( volatile long* )&ref, 0 );
60}
61
62#endif // _TORQUE_PLATFORM_PLATFORMINTRINSICS_VISUALC_H_
63