NVML C++ bindings  1.0.0
This is the C++ bindings documentation for NVML's libpmemobj.
 All Classes Files Functions Variables Typedefs Pages
Functions
make_persistent_atomic.hpp File Reference

Persistent_ptr atomic allocation functions for objects. More...

#include "libpmemobj++/detail/check_persistent_ptr_array.hpp"
#include "libpmemobj++/detail/common.hpp"
#include "libpmemobj++/detail/make_atomic_impl.hpp"
#include "libpmemobj++/detail/pexceptions.hpp"
#include "libpmemobj++/pool.hpp"
#include "libpmemobj/atomic_base.h"
#include <tuple>

Go to the source code of this file.

Functions

template<typename T , typename... Args>
void nvml::obj::make_persistent_atomic (pool_base &pool, typename detail::pp_if_not_array< T >::type &ptr, Args &&...args)
 Atomically allocate and construct an object. More...
 
template<typename T >
void nvml::obj::delete_persistent_atomic (typename detail::pp_if_not_array< T >::type &ptr) noexcept
 Atomically deallocate an object. More...
 

Detailed Description

Persistent_ptr atomic allocation functions for objects.

The typical usage examples would be:

#include <fcntl.h>
using namespace nvml::obj;
void
make_persistent_atomic_example()
{
struct compound_type {
compound_type(int val, double dval)
: some_variable(val), some_other_variable(dval)
{
}
void
set_some_variable(int val)
{
some_variable = val;
}
p<int> some_variable;
p<double> some_other_variable;
};
// pool root structure
struct root {
};
// create a pmemobj pool
auto pop = pool<root>::create("poolfile", "layout", PMEMOBJ_MIN_POOL);
auto proot = pop.get_root();
// typical usage schemes
// atomic allocation and construction with arguments passing
make_persistent_atomic<compound_type>(pop, proot->comp, 1, 2.0);
// atomic object deallocation, ~compound_type() is not called
delete_persistent<compound_type>(proot->comp);
// error prone cases
transaction::exec_tx(pop, [&] {
// possible invalid state in case of transaction abort
make_persistent_atomic<compound_type>(pop, proot->comp, 1, 1.3);
delete_persistent_atomic<compound_type>(proot->comp);
});
}