mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-01 19:02:19 +00:00
pass the pointer to shared memory around, instead of using a global
This commit is contained in:
parent
8307a194e1
commit
95fe9cbccd
6 changed files with 68 additions and 55 deletions
|
@ -44,8 +44,6 @@ pub fn expectFailedStartSharedFile() callconv(.C) [*]u8 {
|
|||
|
||||
const ptr = @ptrCast([*]u8, shared_ptr);
|
||||
|
||||
SHARED_BUFFER = ptr[0..length];
|
||||
|
||||
return ptr;
|
||||
} else {
|
||||
unreachable;
|
||||
|
@ -81,17 +79,11 @@ pub fn readSharedBufferEnv() callconv(.C) void {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_atomic_ptr() *Atomic(u32) {
|
||||
const usize_ptr = @ptrCast([*]u32, @alignCast(@alignOf(usize), SHARED_BUFFER.ptr));
|
||||
const atomic_ptr = @ptrCast(*Atomic(u32), &usize_ptr[5]);
|
||||
|
||||
return atomic_ptr;
|
||||
}
|
||||
|
||||
pub fn expectFailedFinalize() callconv(.C) void {
|
||||
pub fn notifyParent(shared_buffer: [*]u8, tag: u32) callconv(.C) void {
|
||||
if (builtin.os.tag == .macos or builtin.os.tag == .linux) {
|
||||
const atomic_ptr = get_atomic_ptr();
|
||||
atomic_ptr.storeUnchecked(1);
|
||||
const usize_ptr = @ptrCast([*]u32, @alignCast(@alignOf(usize), shared_buffer));
|
||||
const atomic_ptr = @ptrCast(*Atomic(u32), &usize_ptr[5]);
|
||||
atomic_ptr.storeUnchecked(tag);
|
||||
|
||||
// wait till the parent is done before proceeding
|
||||
const Ordering = std.atomic.Ordering;
|
||||
|
@ -101,15 +93,10 @@ pub fn expectFailedFinalize() callconv(.C) void {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn sendDbg() callconv(.C) void {
|
||||
if (builtin.os.tag == .macos or builtin.os.tag == .linux) {
|
||||
const atomic_ptr = get_atomic_ptr();
|
||||
atomic_ptr.storeUnchecked(2);
|
||||
|
||||
// wait till the parent is done before proceeding
|
||||
const Ordering = std.atomic.Ordering;
|
||||
while (atomic_ptr.load(Ordering.Acquire) != 0) {
|
||||
std.atomic.spinLoopHint();
|
||||
}
|
||||
}
|
||||
pub fn notifyParentExpect(shared_buffer: [*]u8) callconv(.C) void {
|
||||
notifyParent(shared_buffer, 1);
|
||||
}
|
||||
|
||||
pub fn notifyParentDbg(shared_buffer: [*]u8) callconv(.C) void {
|
||||
notifyParent(shared_buffer, 2);
|
||||
}
|
||||
|
|
|
@ -172,8 +172,8 @@ comptime {
|
|||
if (builtin.target.cpu.arch != .wasm32) {
|
||||
exportUtilsFn(expect.expectFailedStartSharedBuffer, "expect_failed_start_shared_buffer");
|
||||
exportUtilsFn(expect.expectFailedStartSharedFile, "expect_failed_start_shared_file");
|
||||
exportUtilsFn(expect.expectFailedFinalize, "expect_failed_finalize");
|
||||
exportUtilsFn(expect.sendDbg, "send_dbg");
|
||||
exportUtilsFn(expect.notifyParentExpect, "notify_parent_expect");
|
||||
exportUtilsFn(expect.notifyParentDbg, "notify_parent_dbg");
|
||||
|
||||
// sets the buffer used for expect failures
|
||||
@export(expect.setSharedBuffer, .{ .name = "set_shared_buffer", .linkage = .Weak });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue