annotate libitm/dispatch.h @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
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) 2011-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
2 Contributed by Torvald Riegel <triegel@redhat.com>.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of the GNU Transactional Memory Library (libitm).
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 Libitm 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 Libitm 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 #ifndef DISPATCH_H
kono
parents:
diff changeset
26 #define DISPATCH_H 1
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 #include "libitm.h"
kono
parents:
diff changeset
29 #include "common.h"
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 // Creates ABI load/store methods (can be made virtual or static using M,
kono
parents:
diff changeset
32 // use M2 to create separate methods names for virtual and static)
kono
parents:
diff changeset
33 // The _PV variants are for the pure-virtual methods in the base class.
kono
parents:
diff changeset
34 #define ITM_READ_M(T, LSMOD, M, M2) \
kono
parents:
diff changeset
35 M _ITM_TYPE_##T ITM_REGPARM ITM_##LSMOD##T##M2 (const _ITM_TYPE_##T *ptr) \
kono
parents:
diff changeset
36 { \
kono
parents:
diff changeset
37 return load(ptr, abi_dispatch::LSMOD); \
kono
parents:
diff changeset
38 }
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 #define ITM_READ_M_PV(T, LSMOD, M, M2) \
kono
parents:
diff changeset
41 M _ITM_TYPE_##T ITM_REGPARM ITM_##LSMOD##T##M2 (const _ITM_TYPE_##T *ptr) \
kono
parents:
diff changeset
42 = 0;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 #define ITM_WRITE_M(T, LSMOD, M, M2) \
kono
parents:
diff changeset
45 M void ITM_REGPARM ITM_##LSMOD##T##M2 (_ITM_TYPE_##T *ptr, \
kono
parents:
diff changeset
46 _ITM_TYPE_##T val) \
kono
parents:
diff changeset
47 { \
kono
parents:
diff changeset
48 store(ptr, val, abi_dispatch::LSMOD); \
kono
parents:
diff changeset
49 }
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 #define ITM_WRITE_M_PV(T, LSMOD, M, M2) \
kono
parents:
diff changeset
52 M void ITM_REGPARM ITM_##LSMOD##T##M2 (_ITM_TYPE_##T *ptr, \
kono
parents:
diff changeset
53 _ITM_TYPE_##T val) \
kono
parents:
diff changeset
54 = 0;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 // Creates ABI load/store methods for all load/store modifiers for a particular
kono
parents:
diff changeset
57 // type.
kono
parents:
diff changeset
58 #define CREATE_DISPATCH_METHODS_T(T, M, M2) \
kono
parents:
diff changeset
59 ITM_READ_M(T, R, M, M2) \
kono
parents:
diff changeset
60 ITM_READ_M(T, RaR, M, M2) \
kono
parents:
diff changeset
61 ITM_READ_M(T, RaW, M, M2) \
kono
parents:
diff changeset
62 ITM_READ_M(T, RfW, M, M2) \
kono
parents:
diff changeset
63 ITM_WRITE_M(T, W, M, M2) \
kono
parents:
diff changeset
64 ITM_WRITE_M(T, WaR, M, M2) \
kono
parents:
diff changeset
65 ITM_WRITE_M(T, WaW, M, M2)
kono
parents:
diff changeset
66 #define CREATE_DISPATCH_METHODS_T_PV(T, M, M2) \
kono
parents:
diff changeset
67 ITM_READ_M_PV(T, R, M, M2) \
kono
parents:
diff changeset
68 ITM_READ_M_PV(T, RaR, M, M2) \
kono
parents:
diff changeset
69 ITM_READ_M_PV(T, RaW, M, M2) \
kono
parents:
diff changeset
70 ITM_READ_M_PV(T, RfW, M, M2) \
kono
parents:
diff changeset
71 ITM_WRITE_M_PV(T, W, M, M2) \
kono
parents:
diff changeset
72 ITM_WRITE_M_PV(T, WaR, M, M2) \
kono
parents:
diff changeset
73 ITM_WRITE_M_PV(T, WaW, M, M2)
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 // Creates ABI load/store methods for all types.
kono
parents:
diff changeset
76 // See CREATE_DISPATCH_FUNCTIONS for comments.
kono
parents:
diff changeset
77 #define CREATE_DISPATCH_METHODS(M, M2) \
kono
parents:
diff changeset
78 CREATE_DISPATCH_METHODS_T (U1, M, M2) \
kono
parents:
diff changeset
79 CREATE_DISPATCH_METHODS_T (U2, M, M2) \
kono
parents:
diff changeset
80 CREATE_DISPATCH_METHODS_T (U4, M, M2) \
kono
parents:
diff changeset
81 CREATE_DISPATCH_METHODS_T (U8, M, M2) \
kono
parents:
diff changeset
82 CREATE_DISPATCH_METHODS_T (F, M, M2) \
kono
parents:
diff changeset
83 CREATE_DISPATCH_METHODS_T (D, M, M2) \
kono
parents:
diff changeset
84 CREATE_DISPATCH_METHODS_T (E, M, M2) \
kono
parents:
diff changeset
85 CREATE_DISPATCH_METHODS_T (CF, M, M2) \
kono
parents:
diff changeset
86 CREATE_DISPATCH_METHODS_T (CD, M, M2) \
kono
parents:
diff changeset
87 CREATE_DISPATCH_METHODS_T (CE, M, M2)
kono
parents:
diff changeset
88 #define CREATE_DISPATCH_METHODS_PV(M, M2) \
kono
parents:
diff changeset
89 CREATE_DISPATCH_METHODS_T_PV (U1, M, M2) \
kono
parents:
diff changeset
90 CREATE_DISPATCH_METHODS_T_PV (U2, M, M2) \
kono
parents:
diff changeset
91 CREATE_DISPATCH_METHODS_T_PV (U4, M, M2) \
kono
parents:
diff changeset
92 CREATE_DISPATCH_METHODS_T_PV (U8, M, M2) \
kono
parents:
diff changeset
93 CREATE_DISPATCH_METHODS_T_PV (F, M, M2) \
kono
parents:
diff changeset
94 CREATE_DISPATCH_METHODS_T_PV (D, M, M2) \
kono
parents:
diff changeset
95 CREATE_DISPATCH_METHODS_T_PV (E, M, M2) \
kono
parents:
diff changeset
96 CREATE_DISPATCH_METHODS_T_PV (CF, M, M2) \
kono
parents:
diff changeset
97 CREATE_DISPATCH_METHODS_T_PV (CD, M, M2) \
kono
parents:
diff changeset
98 CREATE_DISPATCH_METHODS_T_PV (CE, M, M2)
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 // Creates memcpy/memmove/memset methods.
kono
parents:
diff changeset
101 #define CREATE_DISPATCH_METHODS_MEM() \
kono
parents:
diff changeset
102 virtual void memtransfer(void *dst, const void* src, size_t size, \
kono
parents:
diff changeset
103 bool may_overlap, ls_modifier dst_mod, ls_modifier src_mod) \
kono
parents:
diff changeset
104 { \
kono
parents:
diff changeset
105 if (size > 0) \
kono
parents:
diff changeset
106 memtransfer_static(dst, src, size, may_overlap, dst_mod, src_mod); \
kono
parents:
diff changeset
107 } \
kono
parents:
diff changeset
108 virtual void memset(void *dst, int c, size_t size, ls_modifier mod) \
kono
parents:
diff changeset
109 { \
kono
parents:
diff changeset
110 if (size > 0) \
kono
parents:
diff changeset
111 memset_static(dst, c, size, mod); \
kono
parents:
diff changeset
112 }
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 #define CREATE_DISPATCH_METHODS_MEM_PV() \
kono
parents:
diff changeset
115 virtual void memtransfer(void *dst, const void* src, size_t size, \
kono
parents:
diff changeset
116 bool may_overlap, ls_modifier dst_mod, ls_modifier src_mod) = 0; \
kono
parents:
diff changeset
117 virtual void memset(void *dst, int c, size_t size, ls_modifier mod) = 0;
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 // Creates ABI load/store functions that can target either a class or an
kono
parents:
diff changeset
121 // object.
kono
parents:
diff changeset
122 #define ITM_READ(T, LSMOD, TARGET, M2) \
kono
parents:
diff changeset
123 _ITM_TYPE_##T ITM_REGPARM _ITM_##LSMOD##T (const _ITM_TYPE_##T *ptr) \
kono
parents:
diff changeset
124 { \
kono
parents:
diff changeset
125 return TARGET ITM_##LSMOD##T##M2(ptr); \
kono
parents:
diff changeset
126 }
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 #define ITM_WRITE(T, LSMOD, TARGET, M2) \
kono
parents:
diff changeset
129 void ITM_REGPARM _ITM_##LSMOD##T (_ITM_TYPE_##T *ptr, _ITM_TYPE_##T val) \
kono
parents:
diff changeset
130 { \
kono
parents:
diff changeset
131 TARGET ITM_##LSMOD##T##M2(ptr, val); \
kono
parents:
diff changeset
132 }
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 // Creates ABI load/store functions for all load/store modifiers for a
kono
parents:
diff changeset
135 // particular type.
kono
parents:
diff changeset
136 #define CREATE_DISPATCH_FUNCTIONS_T(T, TARGET, M2) \
kono
parents:
diff changeset
137 ITM_READ(T, R, TARGET, M2) \
kono
parents:
diff changeset
138 ITM_READ(T, RaR, TARGET, M2) \
kono
parents:
diff changeset
139 ITM_READ(T, RaW, TARGET, M2) \
kono
parents:
diff changeset
140 ITM_READ(T, RfW, TARGET, M2) \
kono
parents:
diff changeset
141 ITM_WRITE(T, W, TARGET, M2) \
kono
parents:
diff changeset
142 ITM_WRITE(T, WaR, TARGET, M2) \
kono
parents:
diff changeset
143 ITM_WRITE(T, WaW, TARGET, M2)
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 // Creates ABI memcpy/memmove/memset functions.
kono
parents:
diff changeset
146 #define ITM_MEMTRANSFER_DEF(TARGET, M2, NAME, READ, WRITE) \
kono
parents:
diff changeset
147 void ITM_REGPARM _ITM_memcpy##NAME(void *dst, const void *src, size_t size) \
kono
parents:
diff changeset
148 { \
kono
parents:
diff changeset
149 TARGET memtransfer##M2 (dst, src, size, \
kono
parents:
diff changeset
150 false, GTM::abi_dispatch::WRITE, GTM::abi_dispatch::READ); \
kono
parents:
diff changeset
151 } \
kono
parents:
diff changeset
152 void ITM_REGPARM _ITM_memmove##NAME(void *dst, const void *src, size_t size) \
kono
parents:
diff changeset
153 { \
kono
parents:
diff changeset
154 TARGET memtransfer##M2 (dst, src, size, \
kono
parents:
diff changeset
155 GTM::abi_dispatch::memmove_overlap_check(dst, src, size, \
kono
parents:
diff changeset
156 GTM::abi_dispatch::WRITE, GTM::abi_dispatch::READ), \
kono
parents:
diff changeset
157 GTM::abi_dispatch::WRITE, GTM::abi_dispatch::READ); \
kono
parents:
diff changeset
158 }
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 #define ITM_MEMSET_DEF(TARGET, M2, WRITE) \
kono
parents:
diff changeset
161 void ITM_REGPARM _ITM_memset##WRITE(void *dst, int c, size_t size) \
kono
parents:
diff changeset
162 { \
kono
parents:
diff changeset
163 TARGET memset##M2 (dst, c, size, GTM::abi_dispatch::WRITE); \
kono
parents:
diff changeset
164 } \
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 // ??? The number of virtual methods is large (7*4 for integers, 7*6 for FP,
kono
parents:
diff changeset
168 // 7*3 for vectors). Is the cache footprint so costly that we should go for
kono
parents:
diff changeset
169 // a small table instead (i.e., only have two virtual load/store methods for
kono
parents:
diff changeset
170 // each supported type)? Note that this doesn't affect custom code paths at
kono
parents:
diff changeset
171 // all because these use only direct calls.
kono
parents:
diff changeset
172 // A large cache footprint could especially decrease HTM performance (due
kono
parents:
diff changeset
173 // to HTM capacity). We could add the modifier (RaR etc.) as parameter, which
kono
parents:
diff changeset
174 // would give us just 4*2+6*2+3*2 functions (so we'd just need one line for
kono
parents:
diff changeset
175 // the integer loads/stores), but then the modifier can be checked only at
kono
parents:
diff changeset
176 // runtime.
kono
parents:
diff changeset
177 // For memcpy/memmove/memset, we just have two virtual methods (memtransfer
kono
parents:
diff changeset
178 // and memset).
kono
parents:
diff changeset
179 #define CREATE_DISPATCH_FUNCTIONS(TARGET, M2) \
kono
parents:
diff changeset
180 CREATE_DISPATCH_FUNCTIONS_T (U1, TARGET, M2) \
kono
parents:
diff changeset
181 CREATE_DISPATCH_FUNCTIONS_T (U2, TARGET, M2) \
kono
parents:
diff changeset
182 CREATE_DISPATCH_FUNCTIONS_T (U4, TARGET, M2) \
kono
parents:
diff changeset
183 CREATE_DISPATCH_FUNCTIONS_T (U8, TARGET, M2) \
kono
parents:
diff changeset
184 CREATE_DISPATCH_FUNCTIONS_T (F, TARGET, M2) \
kono
parents:
diff changeset
185 CREATE_DISPATCH_FUNCTIONS_T (D, TARGET, M2) \
kono
parents:
diff changeset
186 CREATE_DISPATCH_FUNCTIONS_T (E, TARGET, M2) \
kono
parents:
diff changeset
187 CREATE_DISPATCH_FUNCTIONS_T (CF, TARGET, M2) \
kono
parents:
diff changeset
188 CREATE_DISPATCH_FUNCTIONS_T (CD, TARGET, M2) \
kono
parents:
diff changeset
189 CREATE_DISPATCH_FUNCTIONS_T (CE, TARGET, M2) \
kono
parents:
diff changeset
190 ITM_MEMTRANSFER_DEF(TARGET, M2, RnWt, NONTXNAL, W) \
kono
parents:
diff changeset
191 ITM_MEMTRANSFER_DEF(TARGET, M2, RnWtaR, NONTXNAL, WaR) \
kono
parents:
diff changeset
192 ITM_MEMTRANSFER_DEF(TARGET, M2, RnWtaW, NONTXNAL, WaW) \
kono
parents:
diff changeset
193 ITM_MEMTRANSFER_DEF(TARGET, M2, RtWn, R, NONTXNAL) \
kono
parents:
diff changeset
194 ITM_MEMTRANSFER_DEF(TARGET, M2, RtWt, R, W) \
kono
parents:
diff changeset
195 ITM_MEMTRANSFER_DEF(TARGET, M2, RtWtaR, R, WaR) \
kono
parents:
diff changeset
196 ITM_MEMTRANSFER_DEF(TARGET, M2, RtWtaW, R, WaW) \
kono
parents:
diff changeset
197 ITM_MEMTRANSFER_DEF(TARGET, M2, RtaRWn, RaR, NONTXNAL) \
kono
parents:
diff changeset
198 ITM_MEMTRANSFER_DEF(TARGET, M2, RtaRWt, RaR, W) \
kono
parents:
diff changeset
199 ITM_MEMTRANSFER_DEF(TARGET, M2, RtaRWtaR, RaR, WaR) \
kono
parents:
diff changeset
200 ITM_MEMTRANSFER_DEF(TARGET, M2, RtaRWtaW, RaR, WaW) \
kono
parents:
diff changeset
201 ITM_MEMTRANSFER_DEF(TARGET, M2, RtaWWn, RaW, NONTXNAL) \
kono
parents:
diff changeset
202 ITM_MEMTRANSFER_DEF(TARGET, M2, RtaWWt, RaW, W) \
kono
parents:
diff changeset
203 ITM_MEMTRANSFER_DEF(TARGET, M2, RtaWWtaR, RaW, WaR) \
kono
parents:
diff changeset
204 ITM_MEMTRANSFER_DEF(TARGET, M2, RtaWWtaW, RaW, WaW) \
kono
parents:
diff changeset
205 ITM_MEMSET_DEF(TARGET, M2, W) \
kono
parents:
diff changeset
206 ITM_MEMSET_DEF(TARGET, M2, WaR) \
kono
parents:
diff changeset
207 ITM_MEMSET_DEF(TARGET, M2, WaW)
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 // Creates ABI load/store functions that delegate to a transactional memcpy.
kono
parents:
diff changeset
211 #define ITM_READ_MEMCPY(T, LSMOD, TARGET, M2) \
kono
parents:
diff changeset
212 _ITM_TYPE_##T ITM_REGPARM _ITM_##LSMOD##T (const _ITM_TYPE_##T *ptr)\
kono
parents:
diff changeset
213 { \
kono
parents:
diff changeset
214 _ITM_TYPE_##T v; \
kono
parents:
diff changeset
215 TARGET memtransfer##M2(&v, ptr, sizeof(_ITM_TYPE_##T), false, \
kono
parents:
diff changeset
216 GTM::abi_dispatch::NONTXNAL, GTM::abi_dispatch::LSMOD); \
kono
parents:
diff changeset
217 return v; \
kono
parents:
diff changeset
218 }
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 #define ITM_WRITE_MEMCPY(T, LSMOD, TARGET, M2) \
kono
parents:
diff changeset
221 void ITM_REGPARM _ITM_##LSMOD##T (_ITM_TYPE_##T *ptr, _ITM_TYPE_##T val)\
kono
parents:
diff changeset
222 { \
kono
parents:
diff changeset
223 TARGET memtransfer##M2(ptr, &val, sizeof(_ITM_TYPE_##T), false, \
kono
parents:
diff changeset
224 GTM::abi_dispatch::LSMOD, GTM::abi_dispatch::NONTXNAL); \
kono
parents:
diff changeset
225 }
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 #define CREATE_DISPATCH_FUNCTIONS_T_MEMCPY(T, TARGET, M2) \
kono
parents:
diff changeset
228 ITM_READ_MEMCPY(T, R, TARGET, M2) \
kono
parents:
diff changeset
229 ITM_READ_MEMCPY(T, RaR, TARGET, M2) \
kono
parents:
diff changeset
230 ITM_READ_MEMCPY(T, RaW, TARGET, M2) \
kono
parents:
diff changeset
231 ITM_READ_MEMCPY(T, RfW, TARGET, M2) \
kono
parents:
diff changeset
232 ITM_WRITE_MEMCPY(T, W, TARGET, M2) \
kono
parents:
diff changeset
233 ITM_WRITE_MEMCPY(T, WaR, TARGET, M2) \
kono
parents:
diff changeset
234 ITM_WRITE_MEMCPY(T, WaW, TARGET, M2)
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 namespace GTM HIDDEN {
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 struct gtm_transaction_cp;
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 struct method_group
kono
parents:
diff changeset
242 {
kono
parents:
diff changeset
243 // Start using a TM method from this group. This constructs required meta
kono
parents:
diff changeset
244 // data on demand when this method group is actually used. Will be called
kono
parents:
diff changeset
245 // either on first use or after a previous call to fini().
kono
parents:
diff changeset
246 virtual void init() = 0;
kono
parents:
diff changeset
247 // Stop using any method from this group for now. This can be used to
kono
parents:
diff changeset
248 // destruct meta data as soon as this method group is not used anymore.
kono
parents:
diff changeset
249 virtual void fini() = 0;
kono
parents:
diff changeset
250 // This can be overriden to implement more light-weight re-initialization.
kono
parents:
diff changeset
251 virtual void reinit()
kono
parents:
diff changeset
252 {
kono
parents:
diff changeset
253 fini();
kono
parents:
diff changeset
254 init();
kono
parents:
diff changeset
255 }
kono
parents:
diff changeset
256 };
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 // This is the base interface that all TM methods have to implement.
kono
parents:
diff changeset
260 struct abi_dispatch
kono
parents:
diff changeset
261 {
kono
parents:
diff changeset
262 public:
kono
parents:
diff changeset
263 enum ls_modifier { NONTXNAL, R, RaR, RaW, RfW, W, WaR, WaW };
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 private:
kono
parents:
diff changeset
266 // Disallow copies
kono
parents:
diff changeset
267 abi_dispatch(const abi_dispatch &) = delete;
kono
parents:
diff changeset
268 abi_dispatch& operator=(const abi_dispatch &) = delete;
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 public:
kono
parents:
diff changeset
271 // Starts or restarts a transaction. Is called right before executing the
kono
parents:
diff changeset
272 // transactional application code (by either returning from
kono
parents:
diff changeset
273 // gtm_thread::begin_transaction or doing the longjmp when restarting).
kono
parents:
diff changeset
274 // Returns NO_RESTART if the transaction started successfully. Returns
kono
parents:
diff changeset
275 // a real restart reason if it couldn't start and does need to abort. This
kono
parents:
diff changeset
276 // allows TM methods to just give up and delegate ensuring progress to the
kono
parents:
diff changeset
277 // restart mechanism. If it returns a restart reason, this call must be
kono
parents:
diff changeset
278 // idempotent because it will trigger the restart mechanism, which could
kono
parents:
diff changeset
279 // switch to a different TM method.
kono
parents:
diff changeset
280 virtual gtm_restart_reason begin_or_restart() = 0;
kono
parents:
diff changeset
281 // Tries to commit the transaction. Iff this returns true, the transaction
kono
parents:
diff changeset
282 // got committed and all per-transaction data will have been reset.
kono
parents:
diff changeset
283 // Currently, this is called only for the commit of the outermost
kono
parents:
diff changeset
284 // transaction, or when switching to serial mode (which can happen in a
kono
parents:
diff changeset
285 // nested transaction).
kono
parents:
diff changeset
286 // If privatization safety must be ensured in a quiescence-based way, set
kono
parents:
diff changeset
287 // priv_time to a value different to 0. Nontransactional code will not be
kono
parents:
diff changeset
288 // executed after this commit until all registered threads' shared_state is
kono
parents:
diff changeset
289 // larger than or equal to this value.
kono
parents:
diff changeset
290 virtual bool trycommit(gtm_word& priv_time) = 0;
kono
parents:
diff changeset
291 // Rolls back a transaction. Called on abort or after trycommit() returned
kono
parents:
diff changeset
292 // false.
kono
parents:
diff changeset
293 virtual void rollback(gtm_transaction_cp *cp = 0) = 0;
kono
parents:
diff changeset
294 // Returns true iff the snapshot is most recent, which will be the case if
kono
parents:
diff changeset
295 // this transaction cannot be the reason why other transactions cannot
kono
parents:
diff changeset
296 // ensure privatization safety.
kono
parents:
diff changeset
297 virtual bool snapshot_most_recent() = 0;
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 // Return an alternative method that is compatible with the current
kono
parents:
diff changeset
300 // method but supports closed nesting. Return zero if there is none.
kono
parents:
diff changeset
301 // Note that too be compatible, it must be possible to switch to this other
kono
parents:
diff changeset
302 // method on begin of a nested transaction without committing or restarting
kono
parents:
diff changeset
303 // the parent method.
kono
parents:
diff changeset
304 virtual abi_dispatch* closed_nesting_alternative() { return 0; }
kono
parents:
diff changeset
305 // Returns true iff this method group supports the current situation.
kono
parents:
diff changeset
306 // NUMBER_OF_THREADS is the current number of threads that might execute
kono
parents:
diff changeset
307 // transactions.
kono
parents:
diff changeset
308 virtual bool supports(unsigned number_of_threads) { return true; }
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 bool read_only () const { return m_read_only; }
kono
parents:
diff changeset
311 bool write_through() const { return m_write_through; }
kono
parents:
diff changeset
312 bool can_run_uninstrumented_code() const
kono
parents:
diff changeset
313 {
kono
parents:
diff changeset
314 return m_can_run_uninstrumented_code;
kono
parents:
diff changeset
315 }
kono
parents:
diff changeset
316 // Returns true iff this TM method supports closed nesting.
kono
parents:
diff changeset
317 bool closed_nesting() const { return m_closed_nesting; }
kono
parents:
diff changeset
318 // Returns STATE_SERIAL or STATE_SERIAL | STATE_IRREVOCABLE iff the TM
kono
parents:
diff changeset
319 // method only works for serial-mode transactions.
kono
parents:
diff changeset
320 uint32_t requires_serial() const { return m_requires_serial; }
kono
parents:
diff changeset
321 method_group* get_method_group() const { return m_method_group; }
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 static void *operator new(size_t s) { return xmalloc (s); }
kono
parents:
diff changeset
324 static void operator delete(void *p) { free (p); }
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 public:
kono
parents:
diff changeset
327 static bool memmove_overlap_check(void *dst, const void *src, size_t size,
kono
parents:
diff changeset
328 ls_modifier dst_mod, ls_modifier src_mod);
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 // Creates the ABI dispatch methods for loads and stores.
kono
parents:
diff changeset
331 // ??? Should the dispatch table instead be embedded in the dispatch object
kono
parents:
diff changeset
332 // to avoid the indirect lookup in the vtable?
kono
parents:
diff changeset
333 CREATE_DISPATCH_METHODS_PV(virtual, )
kono
parents:
diff changeset
334 // Creates the ABI dispatch methods for memcpy/memmove/memset.
kono
parents:
diff changeset
335 CREATE_DISPATCH_METHODS_MEM_PV()
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 protected:
kono
parents:
diff changeset
338 const bool m_read_only;
kono
parents:
diff changeset
339 const bool m_write_through;
kono
parents:
diff changeset
340 const bool m_can_run_uninstrumented_code;
kono
parents:
diff changeset
341 const bool m_closed_nesting;
kono
parents:
diff changeset
342 const uint32_t m_requires_serial;
kono
parents:
diff changeset
343 method_group* const m_method_group;
kono
parents:
diff changeset
344 abi_dispatch(bool ro, bool wt, bool uninstrumented, bool closed_nesting,
kono
parents:
diff changeset
345 uint32_t requires_serial, method_group* mg) :
kono
parents:
diff changeset
346 m_read_only(ro), m_write_through(wt),
kono
parents:
diff changeset
347 m_can_run_uninstrumented_code(uninstrumented),
kono
parents:
diff changeset
348 m_closed_nesting(closed_nesting), m_requires_serial(requires_serial),
kono
parents:
diff changeset
349 m_method_group(mg)
kono
parents:
diff changeset
350 { }
kono
parents:
diff changeset
351 };
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 }
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 #endif // DISPATCH_H