[CMake] Create a real library instead of an object library for stress tests
[libcds.git] / cds / compiler / gcc / defs.h
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
15     * Redistributions in binary form must reproduce the above copyright notice,
16       this list of conditions and the following disclaimer in the documentation
17       and/or other materials provided with the distribution.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23     FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef CDSLIB_COMPILER_GCC_DEFS_H
32 #define CDSLIB_COMPILER_GCC_DEFS_H
33
34 // Compiler version
35 #define CDS_COMPILER_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
36
37 #if CDS_COMPILER_VERSION < 40800
38 #   error "Compiler version error. GCC version 4.8.0 and above is supported"
39 #endif
40
41 // Compiler name
42 #ifdef __VERSION__
43 #   define  CDS_COMPILER__NAME    ("GNU C++ " __VERSION__)
44 #else
45 #   define  CDS_COMPILER__NAME    "GNU C++"
46 #endif
47 #define  CDS_COMPILER__NICK        "gcc"
48
49 #include <cds/compiler/gcc/compiler_macro.h>
50
51 #define alignof __alignof__
52
53 // ***************************************
54 // C++11 features
55
56 // C++11 inline namespace
57 #define CDS_CXX11_INLINE_NAMESPACE_SUPPORT
58
59 // constexpr
60 #define CDS_CONSTEXPR    constexpr
61
62 // noexcept
63 #define CDS_NOEXCEPT_SUPPORT        noexcept
64 #define CDS_NOEXCEPT_SUPPORT_(expr) noexcept(expr)
65
66 // C++11 thread_local keyword
67 #define CDS_CXX11_THREAD_LOCAL_SUPPORT
68
69 // Full SFINAE support
70 #define CDS_CXX11_SFINAE
71
72 // Inheriting constructors
73 #define CDS_CXX11_INHERITING_CTOR
74
75 // *************************************************
76 // Features
77 // If you run under Thread Sanitizer, pass -DCDS_THREAD_SANITIZER_ENABLED in compiler command line
78 // UPD: Seems, GCC 5+ has predefined macro __SANITIZE_THREAD__, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64354
79 #if defined(__SANITIZE_THREAD__) && !defined(CDS_THREAD_SANITIZER_ENABLED)
80 #   define CDS_THREAD_SANITIZER_ENABLED
81 #endif
82
83 // *************************************************
84 // Alignment macro
85
86 #define CDS_TYPE_ALIGNMENT(n)   __attribute__ ((aligned (n)))
87 #define CDS_CLASS_ALIGNMENT(n)  __attribute__ ((aligned (n)))
88 #define CDS_DATA_ALIGNMENT(n)   __attribute__ ((aligned (n)))
89
90 // Attributes
91 #if CDS_COMPILER_VERSION >= 40900
92 #   if __cplusplus < 201103
93 #       define CDS_DEPRECATED( reason ) __attribute__((deprecated( reason )))
94 #   elif __cplusplus == 201103 // C++11
95 #       define CDS_DEPRECATED( reason ) [[gnu::deprecated(reason)]]
96 #   else  // C++14
97 #       define CDS_DEPRECATED( reason ) [[deprecated(reason)]]
98 #   endif
99 #else
100 #   define CDS_DEPRECATED( reason ) __attribute__((deprecated( reason )))
101 #endif
102
103 #define CDS_NORETURN __attribute__((__noreturn__))
104
105 // likely/unlikely
106
107 #define cds_likely( expr )   __builtin_expect( !!( expr ), 1 )
108 #define cds_unlikely( expr ) __builtin_expect( !!( expr ), 0 )
109
110 // Exceptions
111
112 #if defined( __EXCEPTIONS ) && __EXCEPTIONS == 1
113 #   define CDS_EXCEPTION_ENABLED
114 #endif
115
116 // double-width CAS support
117 // note: gcc-4.8 does not support double-word atomics
118 //       gcc-4.9: a lot of crashes when use DCAS
119 //       gcc-7: 128-bit atomic is not lock-free, see https://gcc.gnu.org/ml/gcc/2017-01/msg00167.html 
120 // You can manually suppress wide-atomic support by defining in compiler command line:
121 //  for 64bit platform: -DCDS_DISABLE_128BIT_ATOMIC
122 //  for 32bit platform: -DCDS_DISABLE_64BIT_ATOMIC
123 #if CDS_COMPILER_VERSION >= 50000
124 #   if CDS_BUILD_BITS == 64
125 #       if !defined( CDS_DISABLE_128BIT_ATOMIC ) && defined( __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 ) && CDS_COMPILER_VERSION < 70000
126 #           define CDS_DCAS_SUPPORT
127 #       endif
128 #   else
129 #       if !defined( CDS_DISABLE_64BIT_ATOMIC ) && defined( __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 )
130 #           define CDS_DCAS_SUPPORT
131 #       endif
132 #   endif
133 #endif
134
135
136 #include <cds/compiler/gcc/compiler_barriers.h>
137
138 #endif // #ifndef CDSLIB_COMPILER_GCC_DEFS_H