libfoedus-core
FOEDUS Core Library
in_commit_epoch_guard.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_XCT_IN_COMMIT_EPOCH_GUARD_HPP_
19 #define FOEDUS_XCT_IN_COMMIT_EPOCH_GUARD_HPP_
20 
21 #include "foedus/assert_nd.hpp"
22 #include "foedus/epoch.hpp"
24 
25 namespace foedus {
26 namespace xct {
27 
59  InCommitEpochGuard(Epoch* in_commit_epoch_address, Epoch conservative_epoch)
60  : in_commit_epoch_address_(in_commit_epoch_address) {
62  *in_commit_epoch_address_ = conservative_epoch;
63  // We assume the caller of this constructer puts a release or ack_rel fence right after this.
64  // So, we don't bother putting the fence here.
65  // assorted::memory_fence_release();
66  }
68  // prohibit reordering any other change BEFORE the update to in_commit_epoch_.
69  // This is to satisfy the first requirement:
70  // ("When this returns 0, this transaction will not publish any more log without getting
71  // recent epoch").
72  // Without this fence, chime can potentially miss the log that has been just published
73  // with the old epoch.
76  // We can also call another memory_order_release here to immediately publish it,
77  // but it's anyway rare. The spinning chime will eventually get the update, so no need.
78  // In non-TSO architecture, this also saves some overhead in critical path.
79  }
81 };
82 } // namespace xct
83 } // namespace foedus
84 #endif // FOEDUS_XCT_IN_COMMIT_EPOCH_GUARD_HPP_
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
Represents a time epoch.
Definition: epoch.hpp:61
Automatically sets in-commit-epoch with appropriate fence during pre-commit protocol.
const Epoch INVALID_EPOCH
A constant epoch object that represents an invalid epoch.
Definition: epoch.hpp:204
Atomic fence methods and load/store with fences that work for both C++11/non-C++11 code...
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
void memory_fence_release()
Equivalent to std::atomic_thread_fence(std::memory_order_release).
InCommitEpochGuard(Epoch *in_commit_epoch_address, Epoch conservative_epoch)