mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
Merge pull request #586 from lightpanda-io/cancel_via_lookup
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / puppeteer-perf (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
wpt / web platform tests (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / puppeteer-perf (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
wpt / web platform tests (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
Change the Linux cancel implementation to match MacOS'
This commit is contained in:
@@ -56,12 +56,10 @@ pub const Loop = struct {
|
|||||||
// This is a weak way to cancel all future Zig callbacks.
|
// This is a weak way to cancel all future Zig callbacks.
|
||||||
zig_ctx_id: u32 = 0,
|
zig_ctx_id: u32 = 0,
|
||||||
|
|
||||||
// The MacOS event loop doesn't support cancellation. We use this to track
|
// We use this to track cancellation ids and, on the timeout callback,
|
||||||
// cancellation ids and, on the timeout callback, we can can check here
|
// we can can check here to see if it's been cancelled.
|
||||||
// to see if it's been cancelled.
|
|
||||||
cancelled: std.AutoHashMapUnmanaged(usize, void),
|
cancelled: std.AutoHashMapUnmanaged(usize, void),
|
||||||
|
|
||||||
cancel_pool: MemoryPool(ContextCancel),
|
|
||||||
timeout_pool: MemoryPool(ContextTimeout),
|
timeout_pool: MemoryPool(ContextTimeout),
|
||||||
event_callback_pool: MemoryPool(EventCallbackContext),
|
event_callback_pool: MemoryPool(EventCallbackContext),
|
||||||
|
|
||||||
@@ -79,7 +77,6 @@ pub const Loop = struct {
|
|||||||
.io = try IO.init(32, 0),
|
.io = try IO.init(32, 0),
|
||||||
.js_events_nb = 0,
|
.js_events_nb = 0,
|
||||||
.zig_events_nb = 0,
|
.zig_events_nb = 0,
|
||||||
.cancel_pool = MemoryPool(ContextCancel).init(alloc),
|
|
||||||
.timeout_pool = MemoryPool(ContextTimeout).init(alloc),
|
.timeout_pool = MemoryPool(ContextTimeout).init(alloc),
|
||||||
.event_callback_pool = MemoryPool(EventCallbackContext).init(alloc),
|
.event_callback_pool = MemoryPool(EventCallbackContext).init(alloc),
|
||||||
};
|
};
|
||||||
@@ -104,7 +101,6 @@ pub const Loop = struct {
|
|||||||
self.io.cancel_all();
|
self.io.cancel_all();
|
||||||
}
|
}
|
||||||
self.io.deinit();
|
self.io.deinit();
|
||||||
self.cancel_pool.deinit();
|
|
||||||
self.timeout_pool.deinit();
|
self.timeout_pool.deinit();
|
||||||
self.event_callback_pool.deinit();
|
self.event_callback_pool.deinit();
|
||||||
self.cancelled.deinit(self.alloc);
|
self.cancelled.deinit(self.alloc);
|
||||||
@@ -175,10 +171,8 @@ pub const Loop = struct {
|
|||||||
loop.alloc.destroy(completion);
|
loop.alloc.destroy(completion);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (comptime CANCEL_SUPPORTED == false) {
|
if (loop.cancelled.remove(@intFromPtr(completion))) {
|
||||||
if (loop.cancelled.remove(@intFromPtr(completion))) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the loop's context id has changed, don't call the js callback
|
// If the loop's context id has changed, don't call the js callback
|
||||||
@@ -221,75 +215,15 @@ pub const Loop = struct {
|
|||||||
return @intFromPtr(completion);
|
return @intFromPtr(completion);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ContextCancel = struct {
|
pub fn cancel(self: *Self, id: usize, js_cbk: ?JSCallback) !void {
|
||||||
loop: *Self,
|
try self.cancelled.put(self.alloc, id, {});
|
||||||
js_cbk: ?JSCallback,
|
if (js_cbk) |cbk| {
|
||||||
js_ctx_id: u32,
|
cbk.call(null) catch {
|
||||||
};
|
self.cbk_error = true;
|
||||||
|
|
||||||
fn cancelCallback(
|
|
||||||
ctx: *ContextCancel,
|
|
||||||
completion: *IO.Completion,
|
|
||||||
result: IO.CancelOneError!void,
|
|
||||||
) void {
|
|
||||||
const loop = ctx.loop;
|
|
||||||
|
|
||||||
defer {
|
|
||||||
loop.removeEvent(.js);
|
|
||||||
loop.cancel_pool.destroy(ctx);
|
|
||||||
loop.alloc.destroy(completion);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the loop's context id has changed, don't call the js callback
|
|
||||||
// function. The callback's memory has already be cleaned and the
|
|
||||||
// events nb reset.
|
|
||||||
if (ctx.js_ctx_id != loop.js_ctx_id) return;
|
|
||||||
|
|
||||||
// TODO: return the error to the callback
|
|
||||||
result catch |err| {
|
|
||||||
switch (err) {
|
|
||||||
error.NotFound => log.debug("cancel callback: {any}", .{err}),
|
|
||||||
else => log.err("cancel callback: {any}", .{err}),
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
// js callback
|
|
||||||
if (ctx.js_cbk) |*js_cbk| {
|
|
||||||
js_cbk.call(null) catch {
|
|
||||||
loop.cbk_error = true;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cancel(self: *Self, id: usize, js_cbk: ?JSCallback) !void {
|
|
||||||
const alloc = self.alloc;
|
|
||||||
if (comptime CANCEL_SUPPORTED == false) {
|
|
||||||
try self.cancelled.put(alloc, id, {});
|
|
||||||
if (js_cbk) |cbk| {
|
|
||||||
cbk.call(null) catch {
|
|
||||||
self.cbk_error = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const comp_cancel: *IO.Completion = @ptrFromInt(id);
|
|
||||||
|
|
||||||
const completion = try alloc.create(Completion);
|
|
||||||
errdefer alloc.destroy(completion);
|
|
||||||
completion.* = undefined;
|
|
||||||
|
|
||||||
const ctx = self.alloc.create(ContextCancel) catch unreachable;
|
|
||||||
ctx.* = ContextCancel{
|
|
||||||
.loop = self,
|
|
||||||
.js_cbk = js_cbk,
|
|
||||||
.js_ctx_id = self.js_ctx_id,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.addEvent(.js);
|
|
||||||
self.io.cancel_one(*ContextCancel, ctx, cancelCallback, completion, comp_cancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset all existing JS callbacks.
|
// Reset all existing JS callbacks.
|
||||||
// The existing events will happen and their memory will be cleanup but the
|
// The existing events will happen and their memory will be cleanup but the
|
||||||
// corresponding callbacks will not be called.
|
// corresponding callbacks will not be called.
|
||||||
|
|||||||
Reference in New Issue
Block a user