1 // Copyright (C) 2013 The Android Open Source Project 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions 6 // are met: 7 // 1. Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // 2. Redistributions in binary form must reproduce the above copyright 10 // notice, this list of conditions and the following disclaimer in the 11 // documentation and/or other materials provided with the distribution. 12 // 3. Neither the name of the project nor the names of its contributors 13 // may be used to endorse or promote products derived from this software 14 // without specific prior written permission. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 // ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 // SUCH DAMAGE. 27 28 #ifndef __GABIXX_CONFIG_H__ 29 #define __GABIXX_CONFIG_H__ 30 31 // Used to tag functions that never return. 32 // IMPORTANT: This must appear at the left of function definitions, 33 // as in: 34 // _GABIXX_NORETURN <return-type> <name>(....) { ... } 35 #define _GABIXX_NORETURN __attribute__((__noreturn__)) 36 37 // Use _GABIXX_NOEXCEPT to use the equivalent of the C++11 noexcept 38 // qualifier at the end of function declarations. 39 // 40 // _GABIXX_NOEXCEPT_() only in C++11 mode to use the noexcept() operator. 41 // _GABIXX_NOEXCEPT_CXX11_ONLY uses noexcept in C++11, nothing otherwise. 42 #if __cplusplus >= 201103L 43 # define _GABIXX_NOEXCEPT noexcept 44 # define _GABIXX_NOEXCEPT_(x) noexcept(x) 45 # define _GABIXX_NOEXCEPT_CXX11_ONLY noexcept 46 #else 47 # define _GABIXX_NOEXCEPT throw() 48 # define _GABIXX_NOEXCEPT_(x) /* nothing */ 49 # define _GABIXX_NOEXCEPT_CXX11_ONLY /* nothing */ 50 #endif 51 52 // Use _GABIXX_HIDDEN to declare internal functions of GAbi++ that should 53 // never be exposed to client code. 54 #define _GABIXX_HIDDEN __attribute__((__visibility__("hidden"))) 55 56 // Use _GABIXX_DEFAULT to prevent user command -fvisibility=hidden 57 #define _GABIXX_DEFAULT __attribute__((__visibility__("default"))) 58 59 // Use _GABIXX_WEAK to define a symbol with weak linkage. 60 #define _GABIXX_WEAK __attribute__((__weak__)) 61 62 // Use _GABIXX_ALWAYS_INLINE to declare a function that shall always be 63 // inlined. Note that the always_inline doesn't make a function inline 64 // per se. 65 #define _GABIXX_ALWAYS_INLINE \ 66 inline __attribute__((__always_inline__)) 67 68 // _GABIXX_HAS_EXCEPTIONS will be 1 if the current source file is compiled 69 // with exceptions support, or 0 otherwise. 70 #if !defined(__clang__) && !defined(__has_feature) 71 #define __has_feature(x) 0 72 #endif 73 74 #if (defined(__clang__) && __has_feature(cxx_exceptions)) || \ 75 (defined(__GNUC__) && defined(__EXCEPTIONS)) 76 #define _GABIXX_HAS_EXCEPTIONS 1 77 #else 78 #define _GABIXX_HAS_EXCEPTIONS 0 79 #endif 80 81 // TODO(digit): Use __atomic_load_acq_rel when available. 82 #define __gabixx_sync_load(address) \ 83 __sync_fetch_and_add((address), (__typeof__(*(address)))0) 84 85 // Clang provides __sync_swap(), but GCC does not. 86 // IMPORTANT: For GCC, __sync_lock_test_and_set has acquire semantics only 87 // so an explicit __sync_synchronize is needed to ensure a full barrier. 88 // TODO(digit): Use __atomic_swap_acq_rel when available. 89 #if defined(__clang__) 90 # define __gabixx_sync_swap(address,value) __sync_swap((address),(value)) 91 #else 92 # define __gabixx_sync_swap(address, value) \ 93 __extension__ ({ \ 94 __typeof__(*(address)) __ret = __sync_lock_test_and_set((address),(value)); \ 95 __sync_synchronize(); \ 96 __ret; \ 97 }) 98 #endif 99 100 #endif // __GABIXX_CONFIG_H__ 101