128
74
return value;
75
}
76
77
void
78
show()
79
{
80
auto node = head;
81
while (node != nullptr) {
82
std::cout << "show: " << node->value << std::endl;
83
node = node->next;
84
}
85
86
std::cout << std::endl;
87
}
88
89
private:
90
queue_node *head = nullptr;
91
queue_node *tail = nullptr;
92
};
• Lines 38-40: We declare layout of the queue_node structure. It stores
an integer value and a pointer to the next node in the list.
• Lines 44-57: We implement push() method which allocates new
node and sets its value.
• Lines 59-75: We implement pop() method which deletes the first
element in the queue.
• Lines 77-87: The show() method walks the list and prints the contents
of each node to standard out.
The preceding queue implementation stores values of type int in a linked list and
provides three basic methods: push(), pop(), and show().
In this section, we will demonstrate how to modify your volatile structure to store
elements in persistent memory with libpmemobj-cpp bindings. All the modifier methods
should provide atomicity and consistency properties which will be guaranteed by the
use of transactions.
Chapter 8 libpmemobj-Cpp: the adaptable language - C++ and persistent memory
Précédent

- 154/457

Suivant