Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 9d770fb

Browse files
committed
mpsc_queue: expose log ptr in pmem_log_type
1 parent d1b444a commit 9d770fb

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

include/libpmemobj++/experimental/mpsc_queue.hpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ class mpsc_queue {
124124
public:
125125
pmem_log_type(size_t size);
126126

127+
pmem::obj::string_view data();
128+
127129
private:
128-
pmem::obj::vector<char> data;
130+
pmem::obj::vector<char> data_;
129131
pmem::obj::p<size_t> written;
130132

131133
friend class mpsc_queue;
@@ -136,14 +138,10 @@ mpsc_queue::mpsc_queue(pmem_log_type &pmem, size_t max_workers)
136138
{
137139
pop = pmem::obj::pool_by_vptr(&pmem);
138140

139-
auto addr = reinterpret_cast<uintptr_t>(&pmem.data[0]);
140-
auto aligned_addr =
141-
pmem::detail::align_up(addr, pmem::detail::CACHELINE_SIZE);
141+
auto buf_data = pmem.data();
142142

143-
buf = reinterpret_cast<char *>(aligned_addr);
144-
buff_size_ = pmem.data.size() - (aligned_addr - addr);
145-
buff_size_ = pmem::detail::align_down(buff_size_,
146-
pmem::detail::CACHELINE_SIZE);
143+
buf = const_cast<char *>(buf_data.data());
144+
buff_size_ = buf_data.size();
147145

148146
ring_buffer = std::unique_ptr<ringbuf::ringbuf_t>(
149147
new ringbuf::ringbuf_t(max_workers, buff_size_));
@@ -225,8 +223,23 @@ mpsc_queue::restore_offsets()
225223
}
226224

227225
mpsc_queue::pmem_log_type::pmem_log_type(size_t size)
228-
: data(size, 0), written(0)
226+
: data_(size, 0), written(0)
227+
{
228+
}
229+
230+
inline pmem::obj::string_view
231+
mpsc_queue::pmem_log_type::data()
229232
{
233+
auto addr = reinterpret_cast<uintptr_t>(&data_[0]);
234+
auto aligned_addr =
235+
pmem::detail::align_up(addr, pmem::detail::CACHELINE_SIZE);
236+
237+
auto size = data_.size() - (aligned_addr - addr);
238+
auto aligned_size =
239+
pmem::detail::align_down(size, pmem::detail::CACHELINE_SIZE);
240+
241+
return pmem::obj::string_view(
242+
reinterpret_cast<const char *>(aligned_addr), aligned_size);
230243
}
231244

232245
inline pmem::detail::id_manager &

0 commit comments

Comments
 (0)