PMDK C++ bindings  1.12-git53.g67ba2be4
This is the C++ bindings documentation for PMDK's libpmemobj.
pool_data.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2019, Intel Corporation */
3 
10 #ifndef LIBPMEMOBJ_CPP_POOL_DATA_HPP
11 #define LIBPMEMOBJ_CPP_POOL_DATA_HPP
12 
13 #include <atomic>
14 #include <functional>
15 
16 namespace pmem
17 {
18 
19 namespace detail
20 {
21 
22 struct pool_data {
23  pool_data()
24  {
25  initialized = false;
26  }
27 
28  /* Set cleanup function if not already set */
29  void
30  set_cleanup(std::function<void()> cleanup)
31  {
32  bool expected = false;
33 
34  /* this is only to protect from concurrent initializations,
35  * there will be no concurrent reads */
36  if (initialized.compare_exchange_strong(
37  expected, true, std::memory_order_release,
38  std::memory_order_relaxed)) {
39  this->cleanup = cleanup;
40  }
41  }
42 
43  std::atomic<bool> initialized;
44  std::function<void()> cleanup;
45 };
46 
47 } /* namespace detail */
48 
49 } /* namespace pmem */
50 
51 #endif /* LIBPMEMOBJ_CPP_POOL_DATA_HPP */
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:15