annotate libatomic/host-config.h @ 144:8f4e72ab4e11

fix segmentation fault caused by nothing next cur_op to end
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 21:23:56 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1 /* Copyright (C) 2012-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
2 Contributed by Richard Henderson <rth@redhat.com>.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of the GNU Atomic Library (libatomic).
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 Libatomic is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
7 under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 the Free Software Foundation; either version 3 of the License, or
kono
parents:
diff changeset
9 (at your option) any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
kono
parents:
diff changeset
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
kono
parents:
diff changeset
14 more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 /* Included after all more target-specific host-config.h. */
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 /* The target may have some OS specific way to implement compare-and-swap. */
kono
parents:
diff changeset
29 #if !defined(atomic_compare_exchange_n) && SIZE(HAVE_ATOMIC_CAS)
kono
parents:
diff changeset
30 # define atomic_compare_exchange_n __atomic_compare_exchange_n
kono
parents:
diff changeset
31 #endif
kono
parents:
diff changeset
32 #if !defined(atomic_compare_exchange_w) && WSIZE(HAVE_ATOMIC_CAS)
kono
parents:
diff changeset
33 # define atomic_compare_exchange_w __atomic_compare_exchange_n
kono
parents:
diff changeset
34 #endif
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 /* For some targets, it may be significantly faster to avoid all barriers
kono
parents:
diff changeset
37 if the user only wants relaxed memory order. Sometimes we don't want
kono
parents:
diff changeset
38 the extra code bloat. In all cases, use the input to avoid warnings. */
kono
parents:
diff changeset
39 #if defined(WANT_SPECIALCASE_RELAXED) && !defined(__OPTIMIZE_SIZE__)
kono
parents:
diff changeset
40 # define maybe_specialcase_relaxed(x) ((x) == __ATOMIC_RELAXED)
kono
parents:
diff changeset
41 #else
kono
parents:
diff changeset
42 # define maybe_specialcase_relaxed(x) ((x) & 0)
kono
parents:
diff changeset
43 #endif
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 /* Similar, but for targets for which the seq_cst model is sufficiently
kono
parents:
diff changeset
46 more expensive than the acq_rel model. */
kono
parents:
diff changeset
47 #if defined(WANT_SPECIALCASE_ACQREL) && !defined(__OPTIMIZE_SIZE__)
kono
parents:
diff changeset
48 # define maybe_specialcase_acqrel(x) ((x) != __ATOMIC_SEQ_CST)
kono
parents:
diff changeset
49 #else
kono
parents:
diff changeset
50 # define maybe_specialcase_acqrel(x) ((x) & 0)
kono
parents:
diff changeset
51 #endif
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 /* The target may have some OS specific way to emit barriers. */
kono
parents:
diff changeset
55 #ifndef pre_post_barrier
kono
parents:
diff changeset
56 static inline void __attribute__((always_inline, artificial))
kono
parents:
diff changeset
57 pre_barrier(int model)
kono
parents:
diff changeset
58 {
kono
parents:
diff changeset
59 if (!maybe_specialcase_relaxed(model))
kono
parents:
diff changeset
60 {
kono
parents:
diff changeset
61 if (maybe_specialcase_acqrel(model))
kono
parents:
diff changeset
62 __atomic_thread_fence (__ATOMIC_ACQ_REL);
kono
parents:
diff changeset
63 else
kono
parents:
diff changeset
64 __atomic_thread_fence (__ATOMIC_SEQ_CST);
kono
parents:
diff changeset
65 }
kono
parents:
diff changeset
66 }
kono
parents:
diff changeset
67 static inline void __attribute__((always_inline, artificial))
kono
parents:
diff changeset
68 post_barrier(int model)
kono
parents:
diff changeset
69 {
kono
parents:
diff changeset
70 pre_barrier(model);
kono
parents:
diff changeset
71 }
kono
parents:
diff changeset
72 #define pre_post_barrier 1
kono
parents:
diff changeset
73 #endif /* pre_post_barrier */
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 /* Similar, but assume that acq_rel is already handled via locks. */
kono
parents:
diff changeset
76 #ifndef pre_post_seq_barrier
kono
parents:
diff changeset
77 static inline void __attribute__((always_inline, artificial))
kono
parents:
diff changeset
78 pre_seq_barrier(int model)
kono
parents:
diff changeset
79 {
kono
parents:
diff changeset
80 }
kono
parents:
diff changeset
81 static inline void __attribute__((always_inline, artificial))
kono
parents:
diff changeset
82 post_seq_barrier(int model)
kono
parents:
diff changeset
83 {
kono
parents:
diff changeset
84 }
kono
parents:
diff changeset
85 #define pre_post_seq_barrier 1
kono
parents:
diff changeset
86 #endif