PMDK C++ bindings  1.8.1
This is the C++ bindings documentation for PMDK's libpmemobj.
Namespaces | Functions
make_persistent_atomic.hpp File Reference

Persistent_ptr atomic allocation functions for objects. More...

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

Go to the source code of this file.

Namespaces

 pmem
 A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509.02235.
 

Functions

template<typename T , typename... Args>
void pmem::obj::make_persistent_atomic (pool_base &pool, typename detail::pp_if_not_array< T >::type &ptr, allocation_flag_atomic flag, Args &&... args)
 Atomically allocate and construct an object. More...
 
template<typename T , typename... Args>
std::enable_if<!detail::is_first_arg_same< allocation_flag_atomic, Args... >::value >::type pmem::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 pmem::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 pmem::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.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::run(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);
});
}

Function Documentation

◆ delete_persistent_atomic()

template<typename T >
void pmem::obj::delete_persistent_atomic ( typename detail::pp_if_not_array< T >::type &  ptr)
noexcept

Atomically deallocate an object.

There is no way to atomically destroy an object. Any object specific cleanup must be performed elsewhere. Do NOT use this inside transactions, as it might lead to undefined behavior in the presence of transaction aborts.

param[in,out] ptr the persistent_ptr whose pointee is to be deallocated.

◆ make_persistent_atomic() [1/2]

template<typename T , typename... Args>
void pmem::obj::make_persistent_atomic ( pool_base pool,
typename detail::pp_if_not_array< T >::type &  ptr,
allocation_flag_atomic  flag,
Args &&...  args 
)

Atomically allocate and construct an object.

Constructor parameters are passed through variadic parameters. Do NOT use this inside transactions, as it might lead to undefined behavior in the presence of transaction aborts.

Parameters
[in,out]poolthe pool from which the object will be allocated.
[in,out]ptrthe persistent pointer to which the allocation will take place.
[in]flagaffects behaviour of allocator
[in]argsvariadic function parameter containing all parameters passed to the objects constructor.
Exceptions
std::bad_allocon allocation failure.

◆ make_persistent_atomic() [2/2]

template<typename T , typename... Args>
std::enable_if<!detail::is_first_arg_same<allocation_flag_atomic, Args...>::value>::type pmem::obj::make_persistent_atomic ( pool_base pool,
typename detail::pp_if_not_array< T >::type &  ptr,
Args &&...  args 
)

Atomically allocate and construct an object.

Constructor parameters are passed through variadic parameters. Do NOT use this inside transactions, as it might lead to undefined behavior in the presence of transaction aborts.

Parameters
[in,out]poolthe pool from which the object will be allocated.
[in,out]ptrthe persistent pointer to which the allocation will take place.
[in]argsvariadic function parameter containing all parameters passed to the objects constructor.
Exceptions
std::bad_allocon allocation failure.
pmem::obj::pool::create
static pool< T > create(const std::string &path, const std::string &layout, std::size_t size=PMEMOBJ_MIN_POOL, mode_t mode=DEFAULT_MODE)
Creates a new transactional object store pool.
Definition: pool.hpp:646
pmem::obj::p
Resides on pmem class.
Definition: p.hpp:64
pool.hpp
C++ pmemobj pool.
pmem::obj::transaction::run
static void run(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:403
transaction.hpp
C++ pmemobj transactions.
pmem::obj::persistent_ptr
Persistent pointer class.
Definition: persistent_ptr.hpp:132
make_persistent_atomic.hpp
Persistent_ptr atomic allocation functions for objects.
p.hpp
Resides on pmem property template.
persistent_ptr.hpp
Persistent smart pointer.