Replace usage of Small_Array(N; T) with [dynamic; N]T in core:nbio for posix systems

This commit is contained in:
gingerBill
2026-03-12 16:46:51 +00:00
parent 43d8c2bb34
commit 6898cbe678

View File

@@ -11,7 +11,6 @@ import "core:strings"
import "core:sys/posix"
import "core:time"
import kq "core:sys/kqueue"
import sa "core:container/small_array"
@(private="package")
_FULLY_SUPPORTED :: true
@@ -23,7 +22,7 @@ _Event_Loop :: struct {
// that would be the same (ident, filter) pair we need to bundle the operations under one kevent.
submitted: map[Queue_Identifier]^Operation,
// Holds all events we want to flush. Flushing is done each tick at which point this is emptied.
pending: sa.Small_Array(QUEUE_SIZE, kq.KEvent),
pending: [dynamic; QUEUE_SIZE]kq.KEvent,
// Holds what should be in `pending` but didn't fit.
// When `pending`is flushed these are moved to `pending`.
overflow: queue.Queue(kq.KEvent),
@@ -116,7 +115,7 @@ _init :: proc(l: ^Event_Loop, allocator: mem.Allocator) -> (rerr: General_Error)
l.kqueue = kqueue
sa.append(&l.pending, kq.KEvent{
append(&l.pending, kq.KEvent{
ident = IDENT_WAKE_UP,
filter = .User,
flags = {.Add, .Enable, .Clear},
@@ -150,7 +149,7 @@ __tick :: proc(l: ^Event_Loop, timeout: time.Duration) -> General_Error {
}
if NBIO_DEBUG {
npending := sa.len(l.pending)
npending := len(l.pending)
if npending > 0 {
debug("queueing", npending, "new events, there are", int(len(l.submitted)), "events pending")
} else {
@@ -177,9 +176,9 @@ __tick :: proc(l: ^Event_Loop, timeout: time.Duration) -> General_Error {
results_buf: [128]kq.KEvent
results := kevent(l, results_buf[:], ts_pointer) or_return
sa.clear(&l.pending)
clear(&l.pending)
for overflow in queue.pop_front_safe(&l.overflow) {
sa.append(&l.pending, overflow) or_break
(append(&l.pending, overflow) != 0) or_break
}
l.now = time.now()
@@ -202,7 +201,7 @@ __tick :: proc(l: ^Event_Loop, timeout: time.Duration) -> General_Error {
kevent :: proc(l: ^Event_Loop, buf: []kq.KEvent, ts: ^posix.timespec) -> ([]kq.KEvent, General_Error) {
for {
new_events, err := kq.kevent(l.kqueue, sa.slice(&l.pending), buf, ts)
new_events, err := kq.kevent(l.kqueue, l.pending[:], buf, ts)
#partial switch err {
case nil:
assert(new_events >= 0)
@@ -1188,7 +1187,7 @@ add_pending :: proc(op: ^Operation, filter: kq.Filter, ident: uintptr) {
}
append_pending :: #force_inline proc(l: ^Event_Loop, ev: kq.KEvent) {
if !sa.append(&l.pending, ev) {
if append(&l.pending, ev) == 0 {
warn("queue is full, adding to overflow, should QUEUE_SIZE be increased?")
_, err := queue.append(&l.overflow, ev)
ensure(err == nil, "allocation failure")
@@ -1325,7 +1324,7 @@ timeout_and_delete :: proc(target: ^Operation) {
flags = {.Add, .Enable, .One_Shot},
udata = target._impl.next,
}
if !sa.append(&target.l.pending, ev) {
if append(&target.l.pending, ev) == 0 {
warn("just removed the head operation of a list of multiple, and the queue is full, have to force this update through inefficiently")
// This has to happen the next time we submit or we could have udata pointing wrong.
// Very inefficient but probably never hit.