131
81
if (head == nullptr)
82
tail = nullptr;
83
});
84
85
return value;
86
}
The logic of pop() is wrapped within a libpmemobj-cpp transaction. The only
additional modification is to exchange call to volatile delete with transactional
pmem::obj::delete_persistent<>().
The show() method does not modify anything on either volatile DRAM or persistent
memory, so we do not need to make any changes to it since the pmem:obj::persistent_
ptr implementation provides operator->.
To start using the persistent version of this queue example, our application can
associate it with a root object. Listing 8-10 presents an example application that uses our
persistent queue.
Listing 8-10. Example of application that uses a persistent queue
39
#include "persistent_queue.hpp"
40
41
enum queue_op {
42
PUSH,
43
POP,
44
SHOW,
45
EXIT,
46
MAX_OPS,
47
};
48
49
const char *ops_str[MAX_OPS] = {"push", "pop", "show", "exit"};
50
51
queue_op
52
parse_queue_ops(const std::string &ops)
53
{
54
for (int i = 0; i < MAX_OPS; i++) {
55
if (ops == ops_str[i]) {
56
return (queue_op)i;
Chapter 8 libpmemobj-Cpp: the adaptable language - C++ and persistent memory
81
if (head == nullptr)
82
tail = nullptr;
83
});
84
85
return value;
86
}
The logic of pop() is wrapped within a libpmemobj-cpp transaction. The only
additional modification is to exchange call to volatile delete with transactional
pmem::obj::delete_persistent<>().
The show() method does not modify anything on either volatile DRAM or persistent
memory, so we do not need to make any changes to it since the pmem:obj::persistent_
ptr implementation provides operator->.
To start using the persistent version of this queue example, our application can
associate it with a root object. Listing 8-10 presents an example application that uses our
persistent queue.
Listing 8-10. Example of application that uses a persistent queue
39
#include "persistent_queue.hpp"
40
41
enum queue_op {
42
PUSH,
43
POP,
44
SHOW,
45
EXIT,
46
MAX_OPS,
47
};
48
49
const char *ops_str[MAX_OPS] = {"push", "pop", "show", "exit"};
50
51
queue_op
52
parse_queue_ops(const std::string &ops)
53
{
54
for (int i = 0; i < MAX_OPS; i++) {
55
if (ops == ops_str[i]) {
56
return (queue_op)i;
Chapter 8 libpmemobj-Cpp: the adaptable language - C++ and persistent memory
