Fix submission ring overflow & ring_data_t reuse conflicts
This commit is contained in:
+26
-3
@@ -7,16 +7,23 @@ ring_loop_t::ring_loop_t(int qd)
|
||||
{
|
||||
throw std::runtime_error(std::string("io_uring_queue_init: ") + strerror(-ret));
|
||||
}
|
||||
ring_data = (struct ring_data_t*)malloc(sizeof(ring_data_t) * ring.sq.ring_sz);
|
||||
if (!ring_data)
|
||||
free_ring_data_ptr = *ring.cq.kring_entries;
|
||||
ring_datas = (struct ring_data_t*)malloc(sizeof(ring_data_t) * free_ring_data_ptr);
|
||||
free_ring_data = (int*)malloc(sizeof(int) * free_ring_data_ptr);
|
||||
if (!ring_datas || !free_ring_data)
|
||||
{
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
for (int i = 0; i < free_ring_data_ptr; i++)
|
||||
{
|
||||
free_ring_data[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
ring_loop_t::~ring_loop_t()
|
||||
{
|
||||
free(ring_data);
|
||||
free(free_ring_data);
|
||||
free(ring_datas);
|
||||
io_uring_queue_exit(&ring);
|
||||
}
|
||||
|
||||
@@ -52,6 +59,7 @@ void ring_loop_t::loop()
|
||||
d->res = cqe->res;
|
||||
d->callback(d);
|
||||
}
|
||||
free_ring_data[free_ring_data_ptr++] = d - ring_datas;
|
||||
io_uring_cqe_seen(&ring, cqe);
|
||||
}
|
||||
do
|
||||
@@ -63,3 +71,18 @@ void ring_loop_t::loop()
|
||||
}
|
||||
} while (loop_again);
|
||||
}
|
||||
|
||||
unsigned ring_loop_t::save()
|
||||
{
|
||||
return ring.sq.sqe_tail;
|
||||
}
|
||||
|
||||
void ring_loop_t::restore(unsigned sqe_tail)
|
||||
{
|
||||
assert(ring.sq.sqe_tail >= sqe_tail);
|
||||
for (unsigned i = sqe_tail; i < ring.sq.sqe_tail; i++)
|
||||
{
|
||||
free_ring_data[free_ring_data_ptr++] = ((ring_data_t*)ring.sq.sqes[i & *ring.sq.kring_mask].user_data) - ring_datas;
|
||||
}
|
||||
ring.sq.sqe_tail = sqe_tail;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user