aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/base.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/base.zig')
-rw-r--r--src/bun.js/base.zig30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig
index c964c1d95..27f40eeab 100644
--- a/src/bun.js/base.zig
+++ b/src/bun.js/base.zig
@@ -2122,6 +2122,11 @@ pub export fn MarkedArrayBuffer_deallocator(bytes_: *anyopaque, _: *anyopaque) v
// zig's memory allocator interface won't work here
// mimalloc knows the size of things
// but we don't
+ // if (comptime Environment.allow_assert) {
+ // std.debug.assert(mimalloc.mi_check_owned(bytes_) or
+ // mimalloc.mi_heap_check_owned(JSC.VirtualMachine.get().arena.heap.?, bytes_));
+ // }
+
mimalloc.mi_free(bytes_);
}
@@ -3285,6 +3290,15 @@ pub const PollRef = struct {
this.status = .inactive;
vm.uws_event_loop.?.unref();
}
+
+ /// From another thread, Prevent a poll from keeping the process alive.
+ pub fn unrefConcurrently(this: *PollRef, vm: *JSC.VirtualMachine) void {
+ if (this.status != .active)
+ return;
+ this.status = .inactive;
+ vm.uws_event_loop.?.unrefConcurrently();
+ }
+
/// Prevent a poll from keeping the process alive on the next tick.
pub fn unrefOnNextTick(this: *PollRef, vm: *JSC.VirtualMachine) void {
if (this.status != .active)
@@ -3293,6 +3307,14 @@ pub const PollRef = struct {
vm.pending_unref_counter +|= 1;
}
+ /// From another thread, prevent a poll from keeping the process alive on the next tick.
+ pub fn unrefOnNextTickConcurrently(this: *PollRef, vm: *JSC.VirtualMachine) void {
+ if (this.status != .active)
+ return;
+ this.status = .inactive;
+ _ = @atomicRmw(@TypeOf(vm.pending_unref_counter), &vm.pending_unref_counter, .Add, 1, .Monotonic);
+ }
+
/// Allow a poll to keep the process alive.
pub fn ref(this: *PollRef, vm: *JSC.VirtualMachine) void {
if (this.status != .inactive)
@@ -3300,6 +3322,14 @@ pub const PollRef = struct {
this.status = .active;
vm.uws_event_loop.?.ref();
}
+
+ /// Allow a poll to keep the process alive.
+ pub fn refConcurrently(this: *PollRef, vm: *JSC.VirtualMachine) void {
+ if (this.status != .inactive)
+ return;
+ this.status = .active;
+ vm.uws_event_loop.?.refConcurrently();
+ }
};
const KQueueGenerationNumber = if (Environment.isMac and Environment.allow_assert) usize else u0;