libfoedus-core
FOEDUS Core Library
snapshot_id.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_SNAPSHOT_SNAPSHOT_ID_HPP_
19 #define FOEDUS_SNAPSHOT_SNAPSHOT_ID_HPP_
20 #include <stdint.h>
21 
22 #include "foedus/assert_nd.hpp"
23 
29 namespace foedus {
30 namespace snapshot {
43 typedef uint16_t SnapshotId;
44 
45 const SnapshotId kNullSnapshotId = 0;
46 
52 inline SnapshotId increment(SnapshotId id) {
53  ASSERT_ND(id != kNullSnapshotId);
54  ++id;
55  if (id == kNullSnapshotId) {
56  return 1; // wrap around, and skip 0.
57  } else {
58  return id;
59  }
60 }
61 
72 typedef uint32_t BufferPosition;
73 
74 inline BufferPosition to_buffer_position(uint64_t byte_position) {
75  ASSERT_ND(byte_position % 8 == 0);
76  return byte_position >> 3;
77 }
78 inline uint64_t from_buffer_position(BufferPosition buffer_position) {
79  return static_cast<uint64_t>(buffer_position) << 3;
80 }
81 } // namespace snapshot
82 } // namespace foedus
83 #endif // FOEDUS_SNAPSHOT_SNAPSHOT_ID_HPP_
BufferPosition to_buffer_position(uint64_t byte_position)
Definition: snapshot_id.hpp:74
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
uint32_t BufferPosition
Represents a position in some buffer.
Definition: snapshot_id.hpp:72
uint64_t from_buffer_position(BufferPosition buffer_position)
Definition: snapshot_id.hpp:78
SnapshotId increment(SnapshotId id)
Increment SnapshotId.
Definition: snapshot_id.hpp:52
uint16_t SnapshotId
Unique ID of Snapshot.
Definition: snapshot_id.hpp:43
const SnapshotId kNullSnapshotId
Definition: snapshot_id.hpp:45
#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