Skip to content

Commit d5a471f

Browse files
kkuehlzjhunsaker
authored andcommitted
[async]: Change chunk_ptr_ -> chunk_ref_
1 parent 27ce5fd commit d5a471f

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

category/async/io.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ namespace detail
148148

149149
AsyncIO::AsyncIO(class storage_pool &pool, monad::io::Buffers &rwbuf)
150150
: owning_tid_(get_tl_tid())
151+
, storage_pool_{std::addressof(pool)}
152+
, cnv_chunk_{pool.chunk(storage_pool::cnv, 0)}
151153
, fds_{-1, -1}
152154
, uring_(rwbuf.ring())
153155
, wr_uring_(rwbuf.wr_ring())
@@ -193,25 +195,22 @@ AsyncIO::AsyncIO(class storage_pool &pool, monad::io::Buffers &rwbuf)
193195
MONAD_ASYNC_IO_URING_RETRYABLE(io_uring_submit(ring));
194196
}
195197

196-
storage_pool_ = std::addressof(pool);
197-
cnv_chunk_ = std::addressof(pool.chunk(storage_pool::cnv, 0));
198198
auto count = pool.chunks(storage_pool::seq);
199-
seq_chunks_.reserve(count);
200199
std::vector<int> fds;
201200
fds.reserve(count * 2 + 2);
202201
fds.push_back(cnv_chunk_.io_uring_read_fd);
203202
fds.push_back(cnv_chunk_.io_uring_write_fd);
204203
for (size_t n = 0; n < count; n++) {
205-
seq_chunks_.emplace_back(std::addressof(
206-
pool.chunk(storage_pool::seq, static_cast<uint32_t>(n))));
204+
seq_chunks_.emplace_back(
205+
pool.chunk(storage_pool::seq, static_cast<uint32_t>(n)));
207206
MONAD_ASSERT_PRINTF(
208-
seq_chunks_.back().ptr->capacity() >= MONAD_IO_BUFFERS_WRITE_SIZE,
207+
seq_chunks_.back().chunk.capacity() >= MONAD_IO_BUFFERS_WRITE_SIZE,
209208
"sequential chunk capacity %llu must equal or exceed i/o buffer "
210209
"size %zu",
211-
seq_chunks_.back().ptr->capacity(),
210+
seq_chunks_.back().chunk.capacity(),
212211
MONAD_IO_BUFFERS_WRITE_SIZE);
213212
MONAD_ASSERT(
214-
(seq_chunks_.back().ptr->capacity() %
213+
(seq_chunks_.back().chunk.capacity() %
215214
MONAD_IO_BUFFERS_WRITE_SIZE) == 0);
216215
fds.push_back(seq_chunks_[n].io_uring_read_fd);
217216
fds.push_back(seq_chunks_[n].io_uring_write_fd);
@@ -321,7 +320,7 @@ void AsyncIO::submit_request_sqe_(
321320
ci.io_uring_read_fd,
322321
buffer.data(),
323322
static_cast<unsigned int>(buffer.size()),
324-
ci.ptr->read_fd().second + chunk_and_offset.offset,
323+
ci.chunk.read_fd().second + chunk_and_offset.offset,
325324
0);
326325
sqe->flags |= IOSQE_FIXED_FILE;
327326
switch (prio) {
@@ -373,15 +372,15 @@ void AsyncIO::submit_request_(
373372
ci.io_uring_read_fd,
374373
buffers.front().iov_base,
375374
static_cast<unsigned int>(buffers.front().iov_len),
376-
ci.ptr->read_fd().second + chunk_and_offset.offset);
375+
ci.chunk.read_fd().second + chunk_and_offset.offset);
377376
}
378377
else {
379378
io_uring_prep_readv(
380379
sqe,
381380
ci.io_uring_read_fd,
382381
buffers.data(),
383382
static_cast<unsigned int>(buffers.size()),
384-
ci.ptr->read_fd().second + chunk_and_offset.offset);
383+
ci.chunk.read_fd().second + chunk_and_offset.offset);
385384
}
386385
sqe->flags |= IOSQE_FIXED_FILE;
387386
switch (prio) {
@@ -410,7 +409,7 @@ void AsyncIO::submit_request_(
410409
MONAD_DEBUG_ASSERT(buffer.size() <= WRITE_BUFFER_SIZE);
411410

412411
auto const &ci = seq_chunks_[chunk_and_offset.id];
413-
auto offset = ci.ptr->write_fd(buffer.size()).second;
412+
auto offset = ci.chunk.write_fd(buffer.size()).second;
414413
/* Do sanity check to ensure initiator is definitely appending where
415414
they are supposed to be appending.
416415
*/
@@ -765,7 +764,7 @@ void AsyncIO::dump_fd_to(size_t which, std::filesystem::path const &path)
765764
MONAD_ASSERT_PRINTF(
766765
tofd != -1, "creat failed due to %s", std::strerror(errno));
767766
auto untodfd = make_scope_exit([tofd]() noexcept { ::close(tofd); });
768-
auto fromfd = seq_chunks_[which].ptr->read_fd();
767+
auto fromfd = seq_chunks_[which].chunk.read_fd();
769768
MONAD_ASSERT(fromfd.second <= std::numeric_limits<off64_t>::max());
770769
off64_t off_in = static_cast<off64_t>(fromfd.second);
771770
off64_t off_out = 0;
@@ -774,7 +773,7 @@ void AsyncIO::dump_fd_to(size_t which, std::filesystem::path const &path)
774773
&off_in,
775774
tofd,
776775
&off_out,
777-
seq_chunks_[which].ptr->size(),
776+
seq_chunks_[which].chunk.size(),
778777
0);
779778
MONAD_ASSERT_PRINTF(
780779
copied != -1, "copy_file_range failed due to %s", std::strerror(errno));

category/async/io.hpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,25 @@ class AsyncIO final
6666
private:
6767
friend class read_single_buffer_sender;
6868
using _storage_pool = class storage_pool;
69-
using chunk = _storage_pool::chunk_t;
69+
using chunk_t = _storage_pool::chunk_t;
7070

71-
struct chunk_ptr_
71+
struct chunk_ref_
7272
{
73-
chunk *ptr;
73+
chunk_t &chunk;
7474
int io_uring_read_fd{-1}, io_uring_write_fd{-1}; // NOT POSIX fds!
7575

76-
constexpr chunk_ptr_() = default;
77-
78-
constexpr chunk_ptr_(chunk *ptr_)
79-
: ptr(ptr_)
80-
, io_uring_read_fd(ptr ? ptr->read_fd().first : -1)
81-
, io_uring_write_fd(ptr ? ptr->write_fd(0).first : -1)
76+
constexpr chunk_ref_(chunk_t &chunk_)
77+
: chunk{chunk_}
78+
, io_uring_read_fd{chunk.read_fd().first}
79+
, io_uring_write_fd{chunk.write_fd(0).first}
8280
{
8381
}
8482
};
8583

8684
pid_t const owning_tid_;
8785
class storage_pool *storage_pool_{nullptr};
88-
chunk_ptr_ cnv_chunk_;
89-
std::vector<chunk_ptr_> seq_chunks_;
86+
chunk_ref_ cnv_chunk_;
87+
std::vector<chunk_ref_> seq_chunks_;
9088

9189
struct
9290
{
@@ -175,7 +173,7 @@ class AsyncIO final
175173
"id %zu seq chunks size %zu",
176174
id,
177175
seq_chunks_.size());
178-
return seq_chunks_[id].ptr->capacity();
176+
return seq_chunks_[id].chunk.capacity();
179177
}
180178

181179
//! The instance for this thread

0 commit comments

Comments
 (0)