Skip to content

Commit

Permalink
lib.uring: updated __io_uring_for_each_cqe & io_uring_for_each_cqe
Browse files Browse the repository at this point in the history
- macro & function to return `count` of `cqe` populated.
  • Loading branch information
YoSTEALTH committed Jun 1, 2024
1 parent 1f6714a commit 30a3a6b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/liburing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dynamic_import import importer


__version__ = '2024.5.30'
__version__ = '2024.6.1'


importer(exclude_dir=['lib', 'include'])
Expand Down
13 changes: 9 additions & 4 deletions src/liburing/lib/uring.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ from .io_uring cimport *

cdef extern from '../include/liburing.h' nogil:
''' // macro function
static inline void __io_uring_for_each_cqe(struct io_uring* ring,
unsigned int* head,
static inline unsigned __io_uring_for_each_cqe(struct io_uring* ring,
struct io_uring_cqe* cqe)
{
io_uring_for_each_cqe(ring, head[0], cqe);
unsigned head;
unsigned count = 0;
io_uring_for_each_cqe(ring, head, cqe){
count++;
}
return count;
}
'''
# Library interface to `io_uring`
Expand Down Expand Up @@ -243,7 +248,7 @@ cdef extern from '../include/liburing.h' nogil:
int __io_uring_cqe_index 'io_uring_cqe_index'(__io_uring* ring,
unsigned int ptr,
unsigned int mask)
void __io_uring_for_each_cqe(__io_uring* ring, unsigned int* head, __io_uring_cqe* cqe)
unsigned int __io_uring_for_each_cqe(__io_uring* ring, __io_uring_cqe* cqe)

# Must be called after `io_uring_for_each_cqe()`
void __io_uring_cq_advance 'io_uring_cq_advance'(__io_uring* ring,
Expand Down
5 changes: 2 additions & 3 deletions src/liburing/queue.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ cpdef int io_uring_buf_ring_available(io_uring ring,

cpdef io_uring_sqe io_uring_get_sqe(io_uring ring)

cpdef unsigned int io_uring_for_each_cqe(io_uring ring,
io_uring_cqe cqe,
unsigned int head=?) nogil
cpdef unsigned int io_uring_for_each_cqe(io_uring ring, io_uring_cqe cqe) noexcept nogil


cpdef enum __queue_define__:
LIBURING_UDATA_TIMEOUT = __LIBURING_UDATA_TIMEOUT
Expand Down
14 changes: 8 additions & 6 deletions src/liburing/queue.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,11 @@ cpdef inline io_uring_sqe io_uring_get_sqe(io_uring ring):
sqe.ptr = __io_uring_get_sqe(&ring.ptr)
return sqe
cpdef inline unsigned int io_uring_for_each_cqe(io_uring ring,
io_uring_cqe cqe,
unsigned int head=0) nogil:
__io_uring_for_each_cqe(&ring.ptr, &head, cqe.ptr)
return head
cpdef inline unsigned int io_uring_for_each_cqe(io_uring ring, io_uring_cqe cqe) noexcept nogil:
'''
Example
>>> for i in range(io_uring_for_each_cqe(ring, cqe)):
... cqe[i].res, cqe[i].user_data
123, 123
'''
return __io_uring_for_each_cqe(&ring.ptr, cqe.ptr)
2 changes: 1 addition & 1 deletion test/queue/macro_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_io_uring_for_each_cqe(ring, cqe):
sqe.user_data = 3

liburing.io_uring_submit_and_wait_timeout(ring, cqe, 2)
assert liburing.io_uring_for_each_cqe(ring, cqe) == 3
assert liburing.io_uring_for_each_cqe(ring, cqe) == 2
assert cqe.res == 0
assert cqe.user_data == 2
assert cqe[0].user_data == 2
Expand Down

0 comments on commit 30a3a6b

Please sign in to comment.