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