lockfree: use pointer compression on both x86_64 and on alpha
[boost_lockfree.git] / boost / lockfree / detail / prefix.hpp
blob2387796f76cf355a48e047a7b06fcf1c28baa081
1 // Copyright (C) 2007, 2008, 2009 Tim Blechmann & Thomas Grill
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // Disclaimer: Not a Boost library.
9 #ifndef BOOST_LOCKFREE_PREFIX_HPP_INCLUDED
10 #define BOOST_LOCKFREE_PREFIX_HPP_INCLUDED
12 #include <cassert>
15 #ifdef _WIN32
16 #include <windows.h>
17 #endif
19 #ifdef __APPLE__
20 #include <libkern/OSAtomic.h>
21 #endif
23 #define BOOST_LOCKFREE_CACHELINE_BYTES 64
25 #ifdef _MSC_VER
26 // \note: Must use /Oi option for VC++ to enable intrinsics
27 extern "C" {
28 void __cdecl _ReadWriteBarrier();
29 LONG __cdecl _InterlockedCompareExchange(LONG volatile* Dest,LONG Exchange, LONG Comp);
32 #define BOOST_LOCKFREE_CACHELINE_ALIGNMENT __declspec(align(BOOST_LOCKFREE_CACHELINE_BYTES))
34 #if defined(_M_IX86)
35 #define BOOST_LOCKFREE_DCAS_ALIGNMENT
36 #elif defined(_M_X64) || defined(_M_IA64)
37 #define BOOST_LOCKFREE_PTR_COMPRESSION 1
38 #define BOOST_LOCKFREE_DCAS_ALIGNMENT __declspec(align(16))
39 #endif
41 #endif /* _MSC_VER */
43 #ifdef __GNUC__
45 #define BOOST_LOCKFREE_CACHELINE_ALIGNMENT __attribute__((aligned(BOOST_LOCKFREE_CACHELINE_BYTES)))
47 #ifdef __i386__
48 #define BOOST_LOCKFREE_DCAS_ALIGNMENT
49 #elif defined(__ppc__)
50 #define BOOST_LOCKFREE_DCAS_ALIGNMENT
51 #elif defined(__x86_64__)
52 #define BOOST_LOCKFREE_PTR_COMPRESSION 1
53 #define BOOST_LOCKFREE_DCAS_ALIGNMENT __attribute__((aligned(16)))
54 #elif defined(__alpha__)
55 #define BOOST_LOCKFREE_PTR_COMPRESSION 1
56 #endif
59 #if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2))
60 #include <ext/atomicity.h>
61 #else
62 #include <bits/atomicity.h>
63 #endif
66 #endif /* __GNUC__ */
69 #ifdef USE_ATOMIC_OPS
70 #define AO_REQUIRE_CAS
71 #define AO_USE_PENTIUM4_INSTRS
73 extern "C" {
74 #include "../libatomic_ops/src/atomic_ops.h"
76 #endif
79 #endif /* BOOST_LOCKFREE_PREFIX_HPP_INCLUDED */