Function init [src]

Prototype

pub fn init( ring: *IoUring, allocator: mem.Allocator, group_id: u16, buffer_size: u32, buffers_count: u16, ) !BufferGroup

Parameters

ring: *IoUringallocator: mem.Allocatorgroup_id: u16buffer_size: u32buffers_count: u16

Source

pub fn init( ring: *IoUring, allocator: mem.Allocator, group_id: u16, buffer_size: u32, buffers_count: u16, ) !BufferGroup { const buffers = try allocator.alloc(u8, buffer_size * buffers_count); errdefer allocator.free(buffers); const heads = try allocator.alloc(u32, buffers_count); errdefer allocator.free(heads); const br = try setup_buf_ring(ring.fd, buffers_count, group_id, .{ .inc = true }); buf_ring_init(br); const mask = buf_ring_mask(buffers_count); var i: u16 = 0; while (i < buffers_count) : (i += 1) { const pos = buffer_size * i; const buf = buffers[pos .. pos + buffer_size]; heads[i] = 0; buf_ring_add(br, buf, i, mask, i); } buf_ring_advance(br, buffers_count); return BufferGroup{ .ring = ring, .group_id = group_id, .br = br, .buffers = buffers, .heads = heads, .buffer_size = buffer_size, .buffers_count = buffers_count, }; }