make_persistent_array_atomic.hpp File Reference

Atomic persistent_ptr allocation functions for arrays. More...

`#include "libpmemobj++/detail/array_traits.hpp"`
`#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/atomic_base.h"`
Include dependency graph for make_persistent_array_atomic.hpp:

Go to the source code of this file.

## Functions

template<typename T >
void | pmem::obj::make_persistent_atomic (pool_base &pool, typename detail::pp_if_array< T >::type &ptr, std::size_t N)
| Atomically allocate an array of objects. More...
template<typename T >
void | pmem::obj::make_persistent_atomic (pool_base &pool, typename detail::pp_if_size_array< T >::type &ptr)
| Atomically allocate an array of objects. More...
template<typename T >
void | pmem::obj::delete_persistent_atomic (typename detail::pp_if_array< T >::type &ptr, std::size_t)
| Atomically deallocate an array of objects. More...
template<typename T >
void | pmem::obj::delete_persistent_atomic (typename detail::pp_if_size_array< T >::type &ptr)
| Atomically deallocate an array of objects. More...

## Detailed Description

Atomic persistent_ptr allocation functions for arrays.

The typical usage examples would be:

#include <fcntl.h>
#include <libpmemobj++/make_persistent_array_atomic.hpp>
#include <libpmemobj++/p.hpp>
#include <libpmemobj++/persistent_ptr.hpp>
#include <libpmemobj++/pool.hpp>
#include <libpmemobj++/transaction.hpp>
using namespace pmem::obj;
void
make_persistent_array_atomic_example()
{
struct compound_type {
compound_type() : some_variable(0), some_other_variable(0)
{
}
void
set_some_variable(int val)
{
some_variable = val;
}
p<int> some_variable;
p<double> some_other_variable;
};
// pool root structure
struct root {
persistent_ptr<compound_type[]> comp; //
};
// create a pmemobj pool
auto pop = pool<root>::create("poolfile", "layout", PMEMOBJ_MIN_POOL);
auto proot = pop.get_root();
// typical usage schemes
// atomic array allocation and construction - the compound_type has to
// be default constructible
make_persistent_atomic<compound_type[]>(pop, proot->comp, 20);
persistent_ptr<compound_type[42]> arr;
make_persistent_atomic<compound_type[42]>(pop, arr);
// atomic array deallocation, no destructor being called
delete_persistent_atomic<compound_type[]>(proot->comp, 20);
delete_persistent_atomic<compound_type[42]>(arr);
// error prone cases
transaction::exec_tx(pop, [&] {
// possible invalid state in case of transaction abort
make_persistent_atomic<compound_type[]>(pop, proot->comp, 30);
delete_persistent_atomic<compound_type[]>(proot->comp, 30);
});
}

## Function Documentation

## delete_persistent_atomic() [1/2]

template<typename T >

void pmem::obj::delete_persistent_atomic | ( | typename detail::pp_if_array< T >::type & | ptr,
|  | std::size_t |
| ) |  |

Atomically deallocate an array of objects.

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.

## delete_persistent_atomic() [2/2]

template<typename T >

void pmem::obj::delete_persistent_atomic | ( | typename detail::pp_if_size_array< T >::type & | ptr | ) |

Atomically deallocate an array of objects.

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 >

void pmem::obj::make_persistent_atomic | ( | pool_base & | pool,
|  | typename detail::pp_if_array< T >::type & | ptr,
|  | std::size_t | N
| ) |  |

Atomically allocate an array of objects.

This function can be used to atomically allocate an array of objects. Cannot be used for simple objects. Do NOT use this inside transactions, as it might lead to undefined behavior in the presence of transaction aborts.

Parameters

  [in,out] | pool | the pool from which the object will be allocated.
  [in,out] | ptr | the persistent pointer to which the allocation will take place.
  [in] | N | the number of array elements.

Exceptions

  std::bad_alloc | on allocation failure.

## make_persistent_atomic() [2/2]

template<typename T >

void pmem::obj::make_persistent_atomic | ( | pool_base & | pool,
|  | typename detail::pp_if_size_array< T >::type & | ptr
| ) |  |

Atomically allocate an array of objects.

This function can be used to atomically allocate an array of objects. Cannot be used for simple objects. Do NOT use this inside transactions, as it might lead to undefined behavior in the presence of transaction aborts.

Parameters

  [in,out] | pool | the pool from which the object will be allocated.
  [in,out] | ptr | the persistent pointer to which the allocation will take place.

Exceptions

  std::bad_alloc | on allocation failure.