annotate libitm/method-gl.cc @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1 /* Copyright (C) 2011-2020 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 #include "libitm_i.h"
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 using namespace GTM;
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 namespace {
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 // This group consists of all TM methods that synchronize via just a single
kono
parents:
diff changeset
32 // global lock (or ownership record).
kono
parents:
diff changeset
33 struct gl_mg : public method_group
kono
parents:
diff changeset
34 {
kono
parents:
diff changeset
35 static const gtm_word LOCK_BIT = (~(gtm_word)0 >> 1) + 1;
kono
parents:
diff changeset
36 // We can't use the full bitrange because ~0 in gtm_thread::shared_state has
kono
parents:
diff changeset
37 // special meaning.
kono
parents:
diff changeset
38 static const gtm_word VERSION_MAX = (~(gtm_word)0 >> 1) - 1;
kono
parents:
diff changeset
39 static bool is_locked(gtm_word l) { return l & LOCK_BIT; }
kono
parents:
diff changeset
40 static gtm_word set_locked(gtm_word l) { return l | LOCK_BIT; }
kono
parents:
diff changeset
41 static gtm_word clear_locked(gtm_word l) { return l & ~LOCK_BIT; }
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 // The global ownership record.
kono
parents:
diff changeset
44 // No tail-padding necessary (the virtual functions aren't used frequently).
kono
parents:
diff changeset
45 atomic<gtm_word> orec __attribute__((aligned(HW_CACHELINE_SIZE)));
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 virtual void init()
kono
parents:
diff changeset
48 {
kono
parents:
diff changeset
49 // This store is only executed while holding the serial lock, so relaxed
kono
parents:
diff changeset
50 // memory order is sufficient here.
kono
parents:
diff changeset
51 orec.store(0, memory_order_relaxed);
kono
parents:
diff changeset
52 }
kono
parents:
diff changeset
53 virtual void fini() { }
kono
parents:
diff changeset
54 };
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 static gl_mg o_gl_mg;
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 // The global lock, write-through TM method.
kono
parents:
diff changeset
60 // Acquires the orec eagerly before the first write, and then writes through.
kono
parents:
diff changeset
61 // Reads abort if the global orec's version number changed or if it is locked.
kono
parents:
diff changeset
62 // Currently, writes require undo-logging to prevent deadlock between the
kono
parents:
diff changeset
63 // serial lock and the global orec (writer txn acquires orec, reader txn
kono
parents:
diff changeset
64 // upgrades to serial and waits for all other txns, writer tries to upgrade to
kono
parents:
diff changeset
65 // serial too but cannot, writer cannot abort either, deadlock). We could
kono
parents:
diff changeset
66 // avoid this if the serial lock would allow us to prevent other threads from
kono
parents:
diff changeset
67 // going to serial mode, but this probably is too much additional complexity
kono
parents:
diff changeset
68 // just to optimize this TM method.
kono
parents:
diff changeset
69 // gtm_thread::shared_state is used to store a transaction's current
kono
parents:
diff changeset
70 // snapshot time (or commit time). The serial lock uses ~0 for inactive
kono
parents:
diff changeset
71 // transactions and 0 for active ones. Thus, we always have a meaningful
kono
parents:
diff changeset
72 // timestamp in shared_state that can be used to implement quiescence-based
kono
parents:
diff changeset
73 // privatization safety. This even holds if a writing transaction has the
kono
parents:
diff changeset
74 // lock bit set in its shared_state because this is fine for both the serial
kono
parents:
diff changeset
75 // lock (the value will be smaller than ~0) and privatization safety (we
kono
parents:
diff changeset
76 // validate that no other update transaction comitted before we acquired the
kono
parents:
diff changeset
77 // orec, so we have the most recent timestamp and no other transaction can
kono
parents:
diff changeset
78 // commit until we have committed).
kono
parents:
diff changeset
79 // However, we therefore depend on shared_state not being modified by the
kono
parents:
diff changeset
80 // serial lock during upgrades to serial mode, which is ensured by
kono
parents:
diff changeset
81 // gtm_thread::serialirr_mode by not calling gtm_rwlock::write_upgrade_finish
kono
parents:
diff changeset
82 // before we have committed or rolled back.
kono
parents:
diff changeset
83 class gl_wt_dispatch : public abi_dispatch
kono
parents:
diff changeset
84 {
kono
parents:
diff changeset
85 protected:
kono
parents:
diff changeset
86 static void pre_write(const void *addr, size_t len,
kono
parents:
diff changeset
87 gtm_thread *tx = gtm_thr())
kono
parents:
diff changeset
88 {
kono
parents:
diff changeset
89 gtm_word v = tx->shared_state.load(memory_order_relaxed);
kono
parents:
diff changeset
90 if (unlikely(!gl_mg::is_locked(v)))
kono
parents:
diff changeset
91 {
kono
parents:
diff changeset
92 // Check for and handle version number overflow.
kono
parents:
diff changeset
93 if (unlikely(v >= gl_mg::VERSION_MAX))
kono
parents:
diff changeset
94 tx->restart(RESTART_INIT_METHOD_GROUP);
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 // This validates that we have a consistent snapshot, which is also
kono
parents:
diff changeset
97 // for making privatization safety work (see the class' comments).
kono
parents:
diff changeset
98 // Note that this check here will be performed by the subsequent CAS
kono
parents:
diff changeset
99 // again, so relaxed memory order is fine.
kono
parents:
diff changeset
100 gtm_word now = o_gl_mg.orec.load(memory_order_relaxed);
kono
parents:
diff changeset
101 if (now != v)
kono
parents:
diff changeset
102 tx->restart(RESTART_VALIDATE_WRITE);
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 // CAS global orec from our snapshot time to the locked state.
kono
parents:
diff changeset
105 // We need acquire memory order here to synchronize with other
kono
parents:
diff changeset
106 // (ownership) releases of the orec. We do not need acq_rel order
kono
parents:
diff changeset
107 // because whenever another thread reads from this CAS'
kono
parents:
diff changeset
108 // modification, then it will abort anyway and does not rely on
kono
parents:
diff changeset
109 // any further happens-before relation to be established.
kono
parents:
diff changeset
110 // Also note that unlike in ml_wt's increase of the global time
kono
parents:
diff changeset
111 // base (remember that the global orec is used as time base), we do
kono
parents:
diff changeset
112 // not need require memory order here because we do not need to make
kono
parents:
diff changeset
113 // prior orec acquisitions visible to other threads that try to
kono
parents:
diff changeset
114 // extend their snapshot time.
kono
parents:
diff changeset
115 if (!o_gl_mg.orec.compare_exchange_strong (now, gl_mg::set_locked(now),
kono
parents:
diff changeset
116 memory_order_acquire))
kono
parents:
diff changeset
117 tx->restart(RESTART_LOCKED_WRITE);
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 // We use an explicit fence here to avoid having to use release
kono
parents:
diff changeset
120 // memory order for all subsequent data stores. This fence will
kono
parents:
diff changeset
121 // synchronize with loads of the data with acquire memory order. See
kono
parents:
diff changeset
122 // validate() for why this is necessary.
kono
parents:
diff changeset
123 // Adding require memory order to the prior CAS is not sufficient,
kono
parents:
diff changeset
124 // at least according to the Batty et al. formalization of the
kono
parents:
diff changeset
125 // memory model.
kono
parents:
diff changeset
126 atomic_thread_fence(memory_order_release);
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 // Set shared_state to new value.
kono
parents:
diff changeset
129 tx->shared_state.store(gl_mg::set_locked(now), memory_order_release);
kono
parents:
diff changeset
130 }
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 tx->undolog.log(addr, len);
kono
parents:
diff changeset
133 }
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 static void validate(gtm_thread *tx = gtm_thr())
kono
parents:
diff changeset
136 {
kono
parents:
diff changeset
137 // Check that snapshot is consistent. We expect the previous data load to
kono
parents:
diff changeset
138 // have acquire memory order, or be atomic and followed by an acquire
kono
parents:
diff changeset
139 // fence.
kono
parents:
diff changeset
140 // As a result, the data load will synchronize with the release fence
kono
parents:
diff changeset
141 // issued by the transactions whose data updates the data load has read
kono
parents:
diff changeset
142 // from. This forces the orec load to read from a visible sequence of side
kono
parents:
diff changeset
143 // effects that starts with the other updating transaction's store that
kono
parents:
diff changeset
144 // acquired the orec and set it to locked.
kono
parents:
diff changeset
145 // We therefore either read a value with the locked bit set (and restart)
kono
parents:
diff changeset
146 // or read an orec value that was written after the data had been written.
kono
parents:
diff changeset
147 // Either will allow us to detect inconsistent reads because it will have
kono
parents:
diff changeset
148 // a higher/different value.
kono
parents:
diff changeset
149 gtm_word l = o_gl_mg.orec.load(memory_order_relaxed);
kono
parents:
diff changeset
150 if (l != tx->shared_state.load(memory_order_relaxed))
kono
parents:
diff changeset
151 tx->restart(RESTART_VALIDATE_READ);
kono
parents:
diff changeset
152 }
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 template <typename V> static V load(const V* addr, ls_modifier mod)
kono
parents:
diff changeset
155 {
kono
parents:
diff changeset
156 // Read-for-write should be unlikely, but we need to handle it or will
kono
parents:
diff changeset
157 // break later WaW optimizations.
kono
parents:
diff changeset
158 if (unlikely(mod == RfW))
kono
parents:
diff changeset
159 {
kono
parents:
diff changeset
160 pre_write(addr, sizeof(V));
kono
parents:
diff changeset
161 return *addr;
kono
parents:
diff changeset
162 }
kono
parents:
diff changeset
163 if (unlikely(mod == RaW))
kono
parents:
diff changeset
164 return *addr;
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 // We do not have acquired the orec, so we need to load a value and then
kono
parents:
diff changeset
167 // validate that this was consistent.
kono
parents:
diff changeset
168 // This needs to have acquire memory order (see validate()).
kono
parents:
diff changeset
169 // Alternatively, we can put an acquire fence after the data load but this
kono
parents:
diff changeset
170 // is probably less efficient.
kono
parents:
diff changeset
171 // FIXME We would need an atomic load with acquire memory order here but
kono
parents:
diff changeset
172 // we can't just forge an atomic load for nonatomic data because this
kono
parents:
diff changeset
173 // might not work on all implementations of atomics. However, we need
kono
parents:
diff changeset
174 // the acquire memory order and we can only establish this if we link
kono
parents:
diff changeset
175 // it to the matching release using a reads-from relation between atomic
kono
parents:
diff changeset
176 // loads. Also, the compiler is allowed to optimize nonatomic accesses
kono
parents:
diff changeset
177 // differently than atomic accesses (e.g., if the load would be moved to
kono
parents:
diff changeset
178 // after the fence, we potentially don't synchronize properly anymore).
kono
parents:
diff changeset
179 // Instead of the following, just use an ordinary load followed by an
kono
parents:
diff changeset
180 // acquire fence, and hope that this is good enough for now:
kono
parents:
diff changeset
181 // V v = atomic_load_explicit((atomic<V>*)addr, memory_order_acquire);
kono
parents:
diff changeset
182 V v = *addr;
kono
parents:
diff changeset
183 atomic_thread_fence(memory_order_acquire);
kono
parents:
diff changeset
184 validate();
kono
parents:
diff changeset
185 return v;
kono
parents:
diff changeset
186 }
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 template <typename V> static void store(V* addr, const V value,
kono
parents:
diff changeset
189 ls_modifier mod)
kono
parents:
diff changeset
190 {
kono
parents:
diff changeset
191 if (likely(mod != WaW))
kono
parents:
diff changeset
192 pre_write(addr, sizeof(V));
kono
parents:
diff changeset
193 // FIXME We would need an atomic store here but we can't just forge an
kono
parents:
diff changeset
194 // atomic load for nonatomic data because this might not work on all
kono
parents:
diff changeset
195 // implementations of atomics. However, we need this store to link the
kono
parents:
diff changeset
196 // release fence in pre_write() to the acquire operation in load, which
kono
parents:
diff changeset
197 // is only guaranteed if we have a reads-from relation between atomic
kono
parents:
diff changeset
198 // accesses. Also, the compiler is allowed to optimize nonatomic accesses
kono
parents:
diff changeset
199 // differently than atomic accesses (e.g., if the store would be moved
kono
parents:
diff changeset
200 // to before the release fence in pre_write(), things could go wrong).
kono
parents:
diff changeset
201 // atomic_store_explicit((atomic<V>*)addr, value, memory_order_relaxed);
kono
parents:
diff changeset
202 *addr = value;
kono
parents:
diff changeset
203 }
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 public:
kono
parents:
diff changeset
206 static void memtransfer_static(void *dst, const void* src, size_t size,
kono
parents:
diff changeset
207 bool may_overlap, ls_modifier dst_mod, ls_modifier src_mod)
kono
parents:
diff changeset
208 {
kono
parents:
diff changeset
209 gtm_thread *tx = gtm_thr();
kono
parents:
diff changeset
210 if (dst_mod != WaW && dst_mod != NONTXNAL)
kono
parents:
diff changeset
211 pre_write(dst, size, tx);
kono
parents:
diff changeset
212 // We need at least undo-logging for an RfW src region because we might
kono
parents:
diff changeset
213 // subsequently write there with WaW.
kono
parents:
diff changeset
214 if (src_mod == RfW)
kono
parents:
diff changeset
215 pre_write(src, size, tx);
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 // FIXME We should use atomics here (see store()). Let's just hope that
kono
parents:
diff changeset
218 // memcpy/memmove are good enough.
kono
parents:
diff changeset
219 if (!may_overlap)
kono
parents:
diff changeset
220 ::memcpy(dst, src, size);
kono
parents:
diff changeset
221 else
kono
parents:
diff changeset
222 ::memmove(dst, src, size);
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 if (src_mod != RfW && src_mod != RaW && src_mod != NONTXNAL
kono
parents:
diff changeset
225 && dst_mod != WaW)
kono
parents:
diff changeset
226 validate(tx);
kono
parents:
diff changeset
227 }
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 static void memset_static(void *dst, int c, size_t size, ls_modifier mod)
kono
parents:
diff changeset
230 {
kono
parents:
diff changeset
231 if (mod != WaW)
kono
parents:
diff changeset
232 pre_write(dst, size);
kono
parents:
diff changeset
233 // FIXME We should use atomics here (see store()). Let's just hope that
kono
parents:
diff changeset
234 // memset is good enough.
kono
parents:
diff changeset
235 ::memset(dst, c, size);
kono
parents:
diff changeset
236 }
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 virtual gtm_restart_reason begin_or_restart()
kono
parents:
diff changeset
239 {
kono
parents:
diff changeset
240 // We don't need to do anything for nested transactions.
kono
parents:
diff changeset
241 gtm_thread *tx = gtm_thr();
kono
parents:
diff changeset
242 if (tx->parent_txns.size() > 0)
kono
parents:
diff changeset
243 return NO_RESTART;
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 // Spin until global orec is not locked.
kono
parents:
diff changeset
246 // TODO This is not necessary if there are no pure loads (check txn props).
kono
parents:
diff changeset
247 unsigned i = 0;
kono
parents:
diff changeset
248 gtm_word v;
kono
parents:
diff changeset
249 while (1)
kono
parents:
diff changeset
250 {
kono
parents:
diff changeset
251 // We need acquire memory order here so that this load will
kono
parents:
diff changeset
252 // synchronize with the store that releases the orec in trycommit().
kono
parents:
diff changeset
253 // In turn, this makes sure that subsequent data loads will read from
kono
parents:
diff changeset
254 // a visible sequence of side effects that starts with the most recent
kono
parents:
diff changeset
255 // store to the data right before the release of the orec.
kono
parents:
diff changeset
256 v = o_gl_mg.orec.load(memory_order_acquire);
kono
parents:
diff changeset
257 if (!gl_mg::is_locked(v))
kono
parents:
diff changeset
258 break;
kono
parents:
diff changeset
259 // TODO need method-specific max spin count
kono
parents:
diff changeset
260 if (++i > gtm_spin_count_var)
kono
parents:
diff changeset
261 return RESTART_VALIDATE_READ;
kono
parents:
diff changeset
262 cpu_relax();
kono
parents:
diff changeset
263 }
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 // Everything is okay, we have a snapshot time.
kono
parents:
diff changeset
266 // We don't need to enforce any ordering for the following store. There
kono
parents:
diff changeset
267 // are no earlier data loads in this transaction, so the store cannot
kono
parents:
diff changeset
268 // become visible before those (which could lead to the violation of
kono
parents:
diff changeset
269 // privatization safety). The store can become visible after later loads
kono
parents:
diff changeset
270 // but this does not matter because the previous value will have been
kono
parents:
diff changeset
271 // smaller or equal (the serial lock will set shared_state to zero when
kono
parents:
diff changeset
272 // marking the transaction as active, and restarts enforce immediate
kono
parents:
diff changeset
273 // visibility of a smaller or equal value with a barrier (see
kono
parents:
diff changeset
274 // rollback()).
kono
parents:
diff changeset
275 tx->shared_state.store(v, memory_order_relaxed);
kono
parents:
diff changeset
276 return NO_RESTART;
kono
parents:
diff changeset
277 }
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 virtual bool trycommit(gtm_word& priv_time)
kono
parents:
diff changeset
280 {
kono
parents:
diff changeset
281 gtm_thread* tx = gtm_thr();
kono
parents:
diff changeset
282 gtm_word v = tx->shared_state.load(memory_order_relaxed);
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 // Release the orec but do not reset shared_state, which will be modified
kono
parents:
diff changeset
285 // by the serial lock right after our commit anyway. Also, resetting
kono
parents:
diff changeset
286 // shared state here would interfere with the serial lock's use of this
kono
parents:
diff changeset
287 // location.
kono
parents:
diff changeset
288 if (gl_mg::is_locked(v))
kono
parents:
diff changeset
289 {
kono
parents:
diff changeset
290 // Release the global orec, increasing its version number / timestamp.
kono
parents:
diff changeset
291 // See begin_or_restart() for why we need release memory order here.
kono
parents:
diff changeset
292 v = gl_mg::clear_locked(v) + 1;
kono
parents:
diff changeset
293 o_gl_mg.orec.store(v, memory_order_release);
kono
parents:
diff changeset
294 }
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 // Need to ensure privatization safety. Every other transaction must have
kono
parents:
diff changeset
297 // a snapshot time that is at least as high as our commit time (i.e., our
kono
parents:
diff changeset
298 // commit must be visible to them). Because of proxy privatization, we
kono
parents:
diff changeset
299 // must ensure that even if we are a read-only transaction. See
kono
parents:
diff changeset
300 // ml_wt_dispatch::trycommit() for details: We can't get quite the same
kono
parents:
diff changeset
301 // set of problems because we just use one orec and thus, for example,
kono
parents:
diff changeset
302 // there cannot be concurrent writers -- but we can still get pending
kono
parents:
diff changeset
303 // loads to privatized data when not ensuring privatization safety, which
kono
parents:
diff changeset
304 // is problematic if the program unmaps the privatized memory.
kono
parents:
diff changeset
305 priv_time = v;
kono
parents:
diff changeset
306 return true;
kono
parents:
diff changeset
307 }
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 virtual void rollback(gtm_transaction_cp *cp)
kono
parents:
diff changeset
310 {
kono
parents:
diff changeset
311 // We don't do anything for rollbacks of nested transactions.
kono
parents:
diff changeset
312 if (cp != 0)
kono
parents:
diff changeset
313 return;
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 gtm_thread *tx = gtm_thr();
kono
parents:
diff changeset
316 gtm_word v = tx->shared_state.load(memory_order_relaxed);
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 // Release lock and increment version number to prevent dirty reads.
kono
parents:
diff changeset
319 // Also reset shared state here, so that begin_or_restart() can expect a
kono
parents:
diff changeset
320 // value that is correct wrt. privatization safety.
kono
parents:
diff changeset
321 if (gl_mg::is_locked(v))
kono
parents:
diff changeset
322 {
kono
parents:
diff changeset
323 // With our rollback, global time increases.
kono
parents:
diff changeset
324 v = gl_mg::clear_locked(v) + 1;
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 // First reset the timestamp published via shared_state. Release
kono
parents:
diff changeset
327 // memory order will make this happen after undoing prior data writes.
kono
parents:
diff changeset
328 // This must also happen before we actually release the global orec
kono
parents:
diff changeset
329 // next, so that future update transactions in other threads observe
kono
parents:
diff changeset
330 // a meaningful snapshot time for our transaction; otherwise, they
kono
parents:
diff changeset
331 // could read a shared_store value with the LOCK_BIT set, which can
kono
parents:
diff changeset
332 // break privatization safety because it's larger than the actual
kono
parents:
diff changeset
333 // snapshot time. Note that we only need to consider other update
kono
parents:
diff changeset
334 // transactions because only those will potentially privatize data.
kono
parents:
diff changeset
335 tx->shared_state.store(v, memory_order_release);
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 // Release the global orec, increasing its version number / timestamp.
kono
parents:
diff changeset
338 // See begin_or_restart() for why we need release memory order here,
kono
parents:
diff changeset
339 // and we also need it to make future update transactions read the
kono
parents:
diff changeset
340 // prior update to shared_state too (update transactions acquire the
kono
parents:
diff changeset
341 // global orec with acquire memory order).
kono
parents:
diff changeset
342 o_gl_mg.orec.store(v, memory_order_release);
kono
parents:
diff changeset
343 }
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 }
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 virtual bool snapshot_most_recent()
kono
parents:
diff changeset
348 {
kono
parents:
diff changeset
349 // This is the same check as in validate() except that we do not restart
kono
parents:
diff changeset
350 // on failure but simply return the result.
kono
parents:
diff changeset
351 return o_gl_mg.orec.load(memory_order_relaxed)
kono
parents:
diff changeset
352 == gtm_thr()->shared_state.load(memory_order_relaxed);
kono
parents:
diff changeset
353 }
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 CREATE_DISPATCH_METHODS(virtual, )
kono
parents:
diff changeset
357 CREATE_DISPATCH_METHODS_MEM()
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 gl_wt_dispatch() : abi_dispatch(false, true, false, false, 0, &o_gl_mg)
kono
parents:
diff changeset
360 { }
kono
parents:
diff changeset
361 };
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 } // anon namespace
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 static const gl_wt_dispatch o_gl_wt_dispatch;
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 abi_dispatch *
kono
parents:
diff changeset
368 GTM::dispatch_gl_wt ()
kono
parents:
diff changeset
369 {
kono
parents:
diff changeset
370 return const_cast<gl_wt_dispatch *>(&o_gl_wt_dispatch);
kono
parents:
diff changeset
371 }