-
Notifications
You must be signed in to change notification settings - Fork 0
/
intrinsics.h
44 lines (36 loc) · 1.12 KB
/
intrinsics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//-----------------------------------------------------------------------------
// Application Core Library
// Copyright (c) 2009-2012 DuJardin Consulting, LLC.
// Portions Copyright (c) 2009 GarageGames, Inc.
//-----------------------------------------------------------------------------
#ifndef _PLATFORMINTRINSICS_H_
#define _PLATFORMINTRINSICS_H_
#ifndef _ACL_TYPES_H_
# include "core/types.h"
#endif
#if defined( ACL_COMPILER_VISUALC )
# include "core/intrinsics/intrinsics.visualc.h"
#elif defined ( ACL_COMPILER_GCC )
# include "core/intrinsics/intrinsics.gcc.h"
#else
# error No intrinsics implemented for compiler.
#endif
namespace ACLib
{
//TODO: 64bit safe
template< typename T >
inline bool dCompareAndSwap( T* volatile& refPtr, T* oldPtr, T* newPtr )
{
return dCompareAndSwap( *reinterpret_cast< volatile U32* >( &refPtr ), ( U32 ) oldPtr, ( U32 ) newPtr );
}
// Test-And-Set
inline bool dTestAndSet( volatile U32& ref )
{
return dCompareAndSwap( ref, 0, 1 );
}
inline bool dTestAndSet( volatile U64& ref )
{
return dCompareAndSwap( ref, 0, 1 );
}
};
#endif // _PLATFORMINTRINSICS_H_