Skip to content

Commit

Permalink
update tigerbeetle + add cancelAll
Browse files Browse the repository at this point in the history
  • Loading branch information
krichprollsch committed Feb 11, 2025
1 parent f40f491 commit 97b3f9c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/loop.zig
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ pub const SingleThreaded = struct {
return Self{ .alloc = alloc, .io = io, .events_nb = events_nb };
}

pub fn deinit(self: Self) void {
pub fn deinit(self: *Self) void {
self.cancelAll();
self.io.deinit();
self.alloc.destroy(self.io);
self.alloc.destroy(self.events_nb);
Expand Down Expand Up @@ -98,6 +99,9 @@ pub const SingleThreaded = struct {
fn eventsNb(self: *Self) usize {
return @atomicLoad(usize, self.events_nb, .seq_cst);
}
fn resetEvents(self: *Self) void {
@atomicStore(usize, self.events_nb, 0, .unordered);
}

fn freeCbk(self: *Self, completion: *IO.Completion, ctx: anytype) void {
self.alloc.destroy(completion);
Expand Down Expand Up @@ -169,7 +173,7 @@ pub const SingleThreaded = struct {
fn cancelCallback(
ctx: *ContextCancel,
completion: *IO.Completion,
result: IO.CancelError!void,
result: IO.CancelOneError!void,
) void {
defer ctx.loop.freeCbk(completion, ctx);

Expand Down Expand Up @@ -208,12 +212,17 @@ pub const SingleThreaded = struct {
};

const old_events_nb = self.addEvent();
self.io.cancel(*ContextCancel, ctx, cancelCallback, completion, comp_cancel);
self.io.cancel_one(*ContextCancel, ctx, cancelCallback, completion, comp_cancel);
if (builtin.is_test) {
report("cancel {d}", .{old_events_nb + 1});
}
}

pub fn cancelAll(self: *Self) void {
self.io.cancel_all();
self.resetEvents();
}

// IO callbacks APIs
// -----------------

Expand Down
2 changes: 1 addition & 1 deletion vendor/tigerbeetle-io

0 comments on commit 97b3f9c

Please sign in to comment.