Compare commits

...

2 Commits

Author SHA1 Message Date
Jarred Sumner
7c7363a3b2 Update thread_pool.zig 2025-04-02 19:37:07 -07:00
Jarred Sumner
3407384f23 Update http.zig 2025-04-02 19:36:35 -07:00
2 changed files with 16 additions and 23 deletions

View File

@@ -1508,11 +1508,23 @@ pub const HTTPThread = struct {
return;
{
var batch_ = batch;
while (batch_.pop()) |task| {
// Move the linked list from Batch into AsyncHTTP.next.
// This is kind of unnecessary work.
var next = batch.head;
const head: *AsyncHTTP = @fieldParentPtr("task", next.?);
var tail: *AsyncHTTP = head;
next = if (next.?.node.next) |node| @fieldParentPtr("node", node) else null;
while (next) |task| {
const http: *AsyncHTTP = @fieldParentPtr("task", task);
this.queued_tasks.push(http);
tail.next = http;
tail = http;
const node = task.node.next orelse break;
next = @fieldParentPtr("node", node);
}
// Use pushBatch so we do fewer atomic operations.
this.queued_tasks.pushBatch(head, tail, batch.len);
}
if (this.has_awoken.load(.monotonic))

View File

@@ -88,26 +88,7 @@ pub const Batch = struct {
head: ?*Task = null,
tail: ?*Task = null,
pub fn pop(this: *Batch) ?*Task {
const len = @atomicLoad(usize, &this.len, .monotonic);
if (len == 0) {
return null;
}
const task = this.head.?;
if (task.node.next) |node| {
this.head = @fieldParentPtr("node", node);
} else {
if (task != this.tail.?) unreachable;
this.tail = null;
this.head = null;
}
this.len -= 1;
if (len == 0) {
this.tail = null;
}
return task;
}
pub const pop = @compileError("Iterate through .head in a while loop");
/// Create a batch from a single task.
pub fn from(task: *Task) Batch {