PMDK C++ bindings
1.9
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
38 #ifndef LIBPMEMOBJ_CPP_ENUMERABLE_THREAD_SPECIFIC_HPP
39 #define LIBPMEMOBJ_CPP_ENUMERABLE_THREAD_SPECIFIC_HPP
51 #include <unordered_map>
74 static constexpr
size_t initial_queue_capacity = 1024;
77 std::size_t queue_capacity;
78 std::deque<size_t> queue;
120 using storage_type = Storage;
121 using mutex_type = Mutex;
125 using value_type = T;
126 using size_type =
typename storage_type::size_type;
127 using difference_type =
typename storage_type::difference_type;
128 using reference = value_type &;
129 using const_reference =
const value_type &;
130 using pointer = value_type *;
131 using const_pointer =
const value_type *;
132 using iterator =
typename storage_type::iterator;
133 using const_iterator =
typename storage_type::const_iterator;
136 template <
typename Handler>
137 void initialize(Handler handler = [](reference) {});
149 size_type
size()
const;
154 const_iterator
begin()
const;
155 const_iterator
end()
const;
164 storage_type _storage;
169 inline id_manager::id_manager()
170 : queue_capacity(initial_queue_capacity), queue(initial_queue_capacity, 0)
173 std::iota(queue.begin(), queue.end(), 0);
184 std::unique_lock<std::mutex> lock(mutex);
187 queue.push_front(queue_capacity++);
189 auto front = queue.front();
203 std::unique_lock<std::mutex> lock(mutex);
205 queue.push_front(
id);
231 #if LIBPMEMOBJ_CPP_VG_DRD_ENABLED
232 ANNOTATE_BENIGN_RACE_SIZED(
233 &manager,
sizeof(std::mutex),
234 "https://bugs.kde.org/show_bug.cgi?id=416286");
262 template <
typename T,
typename Mutex,
typename Storage>
265 _storage_size.get_rw() = 0;
271 template <
typename T,
typename Mutex,
typename Storage>
275 auto pop = get_pool();
278 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
279 VALGRIND_HG_DISABLE_CHECKING(&_storage_size,
sizeof(_storage_size));
282 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED || LIBPMEMOBJ_CPP_VG_DRD_ENABLED
283 ANNOTATE_HAPPENS_BEFORE(&_storage_size);
286 _storage_size.get_rw().store(s);
287 pop.persist(_storage_size);
293 template <
typename T,
typename Mutex,
typename Storage>
297 auto s = _storage_size.get_ro().load();
299 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED || LIBPMEMOBJ_CPP_VG_DRD_ENABLED
300 ANNOTATE_HAPPENS_AFTER(&_storage_size);
313 template <
typename T,
typename Mutex,
typename Storage>
314 template <
typename Handler>
318 for (reference e : *
this) {
332 template <
typename T,
typename Mutex,
typename Storage>
333 typename enumerable_thread_specific<T, Mutex, Storage>::reference
336 assert(pmemobj_tx_stage() != TX_STAGE_WORK);
339 auto index = tid.
get();
341 auto cached_size = get_cached_size();
343 if (index >= cached_size) {
344 std::unique_lock<mutex_type> lock(_mutex);
348 auto size = _storage.size();
351 _storage.resize(index + 1);
352 set_cached_size(index + 1);
353 }
else if (size != cached_size) {
354 set_cached_size(size);
363 return _storage[index];
372 template <
typename T,
typename Mutex,
typename Storage>
376 auto pop = get_pool();
379 _storage_size.get_rw() = 0;
389 template <
typename T,
typename Mutex,
typename Storage>
390 typename enumerable_thread_specific<T, Mutex, Storage>::size_type
393 return _storage.size();
401 template <
typename T,
typename Mutex,
typename Storage>
405 return _storage.size() == 0;
413 template <
typename T,
typename Mutex,
typename Storage>
414 typename enumerable_thread_specific<T, Mutex, Storage>::iterator
417 return _storage.begin();
425 template <
typename T,
typename Mutex,
typename Storage>
426 typename enumerable_thread_specific<T, Mutex, Storage>::iterator
429 return _storage.end();
437 template <
typename T,
typename Mutex,
typename Storage>
438 typename enumerable_thread_specific<T, Mutex, Storage>::const_iterator
441 return _storage.begin();
449 template <
typename T,
typename Mutex,
typename Storage>
450 typename enumerable_thread_specific<T, Mutex, Storage>::const_iterator
453 return _storage.end();
463 template <
typename T,
typename Mutex,
typename Storage>
467 auto pop = pmemobj_pool_by_ptr(
this);
468 assert(pop !=
nullptr);
Class for storing thread local data.
Definition: enumerable_thread_specific.hpp:119
Segment table is a data type with a vector-like interface The difference is that it does not do reall...
Definition: segment_vector.hpp:526
size_type size() const
Returns number of elements being stored in the container.
Definition: enumerable_thread_specific.hpp:391
size_t get()
Obtain current thread id.
Definition: enumerable_thread_specific.hpp:254
iterator end()
Returns an iterator to element after the last.
Definition: enumerable_thread_specific.hpp:427
Persistent memory namespace.
Definition: allocation_flag.hpp:44
size_t get()
Obtain unique thread id.
Definition: enumerable_thread_specific.hpp:182
Commonly used functionality.
obj::pool_base get_pool() const noexcept
Private helper function.
Definition: enumerable_thread_specific.hpp:465
static id_manager & get_id_manager()
Get reference to id_manager instance.
Definition: enumerable_thread_specific.hpp:212
Resides on pmem class.
Definition: p.hpp:64
This structure is used for assigning unique thread ids so that those ids will be reused in case of th...
Definition: enumerable_thread_specific.hpp:64
~thread_id_type()
thread_id_type destructor.
Definition: enumerable_thread_specific.hpp:245
static void run(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:422
iterator begin()
Returns an iterator to the beginning.
Definition: enumerable_thread_specific.hpp:415
RAII-style structure for holding thread id.
Definition: enumerable_thread_specific.hpp:82
reference local()
Returns data reference for the current thread.
Definition: enumerable_thread_specific.hpp:334
Pmem-resident shared mutex.
A persistent version of segment vector implementation.
void initialize(Handler handler=[](reference) {})
Initialization method.
Definition: enumerable_thread_specific.hpp:316
size_t get_cached_size()
Get cached storage size and make valgrind annotations.
Definition: enumerable_thread_specific.hpp:295
bool empty() const
Determines if container is empty or not.
Definition: enumerable_thread_specific.hpp:403
thread_id_type()
thread_id_type constructor.
Definition: enumerable_thread_specific.hpp:223
void clear()
Removes all elements from the container.
Definition: enumerable_thread_specific.hpp:374
enumerable_thread_specific()
Constructor.
Definition: enumerable_thread_specific.hpp:263
void set_cached_size(size_t s)
Set cached storage size, persist it and make valgrind annotations.
Definition: enumerable_thread_specific.hpp:273
The non-template pool base class.
Definition: pool.hpp:75
Persistent memory resident shared_mutex implementation.
Definition: shared_mutex.hpp:59
void release(size_t id)
Releases thread id so that it can be reused by other threads.
Definition: enumerable_thread_specific.hpp:201