Home | History | Annotate | Download | only in include
      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 #if __cplusplus >= 201103L
     42 #  define _GABIXX_NOEXCEPT noexcept
     43 #  define _GABIXX_NOEXCEPT_(x) noexcept(x)
     44 #else
     45 #  define _GABIXX_NOEXCEPT throw()
     46 #  define _GABIXX_NOEXCEPT_(x) /* nothing */
     47 #endif
     48 
     49 // Use _GABIXX_HIDDEN to declare internal functions of GAbi++ that should
     50 // never be exposed to client code.
     51 #define _GABIXX_HIDDEN  __attribute__((__visibility__("hidden")))
     52 
     53 // Use _GABIXX_WEAK to define a symbol with weak linkage.
     54 #define _GABIXX_WEAK  __attribute__((__weak__))
     55 
     56 // Use _GABIXX_ALWAYS_INLINE to declare a function that shall always be
     57 // inlined. Note that the always_inline doesn't make a function inline
     58 // per se.
     59 #define _GABIXX_ALWAYS_INLINE \
     60   inline __attribute__((__always_inline__))
     61 
     62 // _GABIXX_HAS_EXCEPTIONS will be 1 if the current source file is compiled
     63 // with exceptions support, or 0 otherwise.
     64 #if !defined(__clang__) && !defined(__has_feature)
     65 #define __has_feature(x) 0
     66 #endif
     67 
     68 #if (defined(__clang__) && __has_feature(cxx_exceptions)) || \
     69     (defined(__GNUC__) && defined(__EXCEPTIONS))
     70 #define _GABIXX_HAS_EXCEPTIONS 1
     71 #else
     72 #define _GABIXX_HAS_EXCEPTIONS 0
     73 #endif
     74 
     75 // TODO(digit): Use __atomic_load_acq_rel when available.
     76 #define __gabixx_sync_load(address)  \
     77     __sync_fetch_and_add((address), (typeof(*(address)))0)
     78 
     79 // Clang provides __sync_swap(), but GCC does not.
     80 // IMPORTANT: For GCC, __sync_lock_test_and_set has acquire semantics only
     81 // so an explicit __sync_synchronize is needed to ensure a full barrier.
     82 // TODO(digit): Use __atomic_swap_acq_rel when available.
     83 #if defined(__clang__)
     84 #  define __gabixx_sync_swap(address,value)  __sync_swap((address),(value))
     85 #else
     86 #  define __gabixx_sync_swap(address, value)  \
     87   __extension__ ({ \
     88     typeof(*(address)) __ret = __sync_lock_test_and_set((address),(value)); \
     89     __sync_synchronize(); \
     90     __ret; \
     91   })
     92 #endif
     93 
     94 #endif  // __GABIXX_CONFIG_H__
     95