common.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (C) 2008-2015 Free Software Foundation, Inc.
  2. Contributed by Richard Henderson <rth@redhat.com>.
  3. This file is part of the GNU Transactional Memory Library (libitm).
  4. Libitm is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /* The following are internal implementation functions and definitions.
  20. To distinguish them from those defined by the Intel ABI, they all
  21. begin with GTM/gtm. */
  22. #ifndef COMMON_H
  23. #define COMMON_H 1
  24. #define UNUSED __attribute__((unused))
  25. #define ALWAYS_INLINE __attribute__((always_inline))
  26. #ifdef HAVE_ATTRIBUTE_VISIBILITY
  27. # define HIDDEN __attribute__((visibility("hidden")))
  28. #else
  29. # define HIDDEN
  30. #endif
  31. #define likely(X) __builtin_expect((X) != 0, 1)
  32. #define unlikely(X) __builtin_expect((X), 0)
  33. namespace GTM HIDDEN {
  34. // Locally defined protected allocation functions.
  35. //
  36. // To avoid dependency on libstdc++ new/delete, as well as to not
  37. // interfere with the wrapping of the global new/delete we wrap for
  38. // the user in alloc_cpp.cc, use class-local versions that defer
  39. // to malloc/free. Recall that operator new/delete does not go through
  40. // normal lookup and so we cannot simply inject a version into the
  41. // GTM namespace.
  42. // If separate_cl is true, the allocator will try to return memory that is on
  43. // cache lines that are not shared with any object used by another thread.
  44. extern void * xmalloc (size_t s, bool separate_cl = false)
  45. __attribute__((malloc, nothrow));
  46. extern void * xcalloc (size_t s, bool separate_cl = false)
  47. __attribute__((malloc, nothrow));
  48. extern void * xrealloc (void *p, size_t s, bool separate_cl = false)
  49. __attribute__((malloc, nothrow));
  50. } // namespace GTM
  51. #endif // COMMON_H