Skip to content

Commit 3400da0

Browse files
committed
simplify add_buffer_back logic
1 parent b63d015 commit 3400da0

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

include/condy/zcrx.hpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,13 @@ class ZeroCopyRxBufferPool {
176176
}
177177

178178
void add_buffer_back(void *ptr, size_t size) noexcept {
179-
if (rq_nr_queued_() == rq_ring_.ring_entries) {
180-
// Flush the refill queue
181-
flush_rq_();
182-
}
183-
assert(rq_nr_queued_() < rq_ring_.ring_entries);
184-
io_uring_zcrx_rqe *rqe;
185-
unsigned rq_mask = rq_ring_.ring_entries - 1;
186-
rqe = &rq_ring_.rqes[rq_ring_.rq_tail & rq_mask];
187-
rqe->off = (static_cast<char *>(ptr) - static_cast<char *>(area_ptr_)) |
188-
area_token_;
189-
rqe->len = static_cast<uint32_t>(size);
190-
io_uring_smp_store_release(rq_ring_.ktail, ++rq_ring_.rq_tail);
191-
if (device_less_) [[unlikely]] {
179+
if (!device_less_) [[likely]] {
180+
if (rq_nr_queued_() == rq_ring_.ring_entries) {
181+
flush_rq_();
182+
}
183+
rq_enqueue_(ptr, size);
184+
} else {
185+
rq_enqueue_(ptr, size);
192186
flush_rq_();
193187
}
194188
}
@@ -262,6 +256,17 @@ class ZeroCopyRxBufferPool {
262256
return io_uring_register(fd, opcode, ctrl, 0);
263257
}
264258

259+
void rq_enqueue_(void *ptr, size_t size) noexcept {
260+
assert(rq_nr_queued_() < rq_ring_.ring_entries);
261+
io_uring_zcrx_rqe *rqe;
262+
unsigned rq_mask = rq_ring_.ring_entries - 1;
263+
rqe = &rq_ring_.rqes[rq_ring_.rq_tail & rq_mask];
264+
rqe->off = (static_cast<char *>(ptr) - static_cast<char *>(area_ptr_)) |
265+
area_token_;
266+
rqe->len = static_cast<uint32_t>(size);
267+
io_uring_smp_store_release(rq_ring_.ktail, ++rq_ring_.rq_tail);
268+
}
269+
265270
void flush_rq_() noexcept {
266271
auto *ring = detail::Context::current().ring();
267272
zcrx_ctrl ctrl = {};

0 commit comments

Comments
 (0)