mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
correct eventfd implementation
This commit is contained in:
@ -94,5 +94,5 @@ fetch(url.href)
|
|||||||
const io = new Uint8ClampedArray(stdin, 4 + place);
|
const io = new Uint8ClampedArray(stdin, 4 + place);
|
||||||
io.set(text);
|
io.set(text);
|
||||||
Atomics.notify(n, 0);
|
Atomics.notify(n, 0);
|
||||||
}, 5000)
|
}, 10000)
|
||||||
})
|
})
|
||||||
|
@ -99,7 +99,6 @@ function readStdin() {
|
|||||||
Atomics.wait(len, 0, 0, 1000);
|
Atomics.wait(len, 0, 0, 1000);
|
||||||
}
|
}
|
||||||
const length = len[0];
|
const length = len[0];
|
||||||
console.error("stdin", length);
|
|
||||||
if (length === 0) {
|
if (length === 0) {
|
||||||
bytes = null;
|
bytes = null;
|
||||||
return;
|
return;
|
||||||
@ -113,6 +112,7 @@ function sleep(ms: number) {
|
|||||||
const buf = new SharedArrayBuffer(4);
|
const buf = new SharedArrayBuffer(4);
|
||||||
const view = new Int32Array(buf);
|
const view = new Int32Array(buf);
|
||||||
view[0] = 1;
|
view[0] = 1;
|
||||||
|
console.error("sleep", ms);
|
||||||
Atomics.wait(view, 0, 1, ms);
|
Atomics.wait(view, 0, 1, ms);
|
||||||
|
|
||||||
|
|
||||||
@ -732,6 +732,7 @@ export const importObject = {
|
|||||||
const has = new Int32Array(files.has);
|
const has = new Int32Array(files.has);
|
||||||
Atomics.store(has, fd - fdStart, 1);
|
Atomics.store(has, fd - fdStart, 1);
|
||||||
Atomics.notify(has, fd - fdStart);
|
Atomics.notify(has, fd - fdStart);
|
||||||
|
if (!mainThread) Atomics.wait(has, fd-fdStart, 1, 1000);
|
||||||
console.error("notify", fd);
|
console.error("notify", fd);
|
||||||
memory.setUint32(nwritten_ptr, nwritten, true);
|
memory.setUint32(nwritten_ptr, nwritten, true);
|
||||||
|
|
||||||
@ -784,6 +785,10 @@ export const importObject = {
|
|||||||
nwritten += iov_len;
|
nwritten += iov_len;
|
||||||
memory.setUint32(nreadPtr, nwritten, true);
|
memory.setUint32(nreadPtr, nwritten, true);
|
||||||
}
|
}
|
||||||
|
const has = new Int32Array(files.has);
|
||||||
|
Atomics.store(has, fd - fdStart, 0)
|
||||||
|
Atomics.notify(has, fd-fdStart);
|
||||||
|
console.error("read", fd);
|
||||||
} else {
|
} else {
|
||||||
const memory = new DataView(zjs.memory.buffer);
|
const memory = new DataView(zjs.memory.buffer);
|
||||||
let nwritten = 0;
|
let nwritten = 0;
|
||||||
@ -795,7 +800,6 @@ export const importObject = {
|
|||||||
const read = Math.min(iov_len, bytes.length);
|
const read = Math.min(iov_len, bytes.length);
|
||||||
const io = new Uint8ClampedArray(zjs.memory.buffer, iov_base, iov_len);
|
const io = new Uint8ClampedArray(zjs.memory.buffer, iov_base, iov_len);
|
||||||
io.set(bytes.slice(0, read));
|
io.set(bytes.slice(0, read));
|
||||||
console.error(bytes[read-1]);
|
|
||||||
bytes = bytes.slice(read);
|
bytes = bytes.slice(read);
|
||||||
if (bytes.length === 0) bytes = null;
|
if (bytes.length === 0) bytes = null;
|
||||||
nwritten += read;
|
nwritten += read;
|
||||||
@ -803,8 +807,6 @@ export const importObject = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
memory.setUint32(nreadPtr, nwritten, true);
|
memory.setUint32(nreadPtr, nwritten, true);
|
||||||
if (nwritten > 0)
|
|
||||||
console.error("fd_read", nwritten);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fd_seek: (...params) => {
|
fd_seek: (...params) => {
|
||||||
@ -940,7 +942,6 @@ export const importObject = {
|
|||||||
} else {
|
} else {
|
||||||
console.warn("notify");
|
console.warn("notify");
|
||||||
notify = true;
|
notify = true;
|
||||||
Atomics.store(has, fd - fdStart, 0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -973,9 +974,9 @@ export const importObject = {
|
|||||||
select(SP_PARM->_checkfd + 1, &fdset, NULL, NULL, &ktimeout)
|
select(SP_PARM->_checkfd + 1, &fdset, NULL, NULL, &ktimeout)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
if (fd == WASI_STDIN_FILENO && WASI_EVENTTYPE_FD_READ == type) {
|
// if (fd == WASI_STDIN_FILENO && WASI_EVENTTYPE_FD_READ == type) {
|
||||||
sleep(5000);
|
// sleep(5000);
|
||||||
}
|
// }
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1064,9 +1065,10 @@ export const importObject = {
|
|||||||
|
|
||||||
...zjs.importObject(),
|
...zjs.importObject(),
|
||||||
};
|
};
|
||||||
|
let pid = 100;
|
||||||
function spawnWorker(instance) {
|
function spawnWorker(instance) {
|
||||||
const worker = new Worker(new URL("worker.ts", import.meta.url), { type: "module" });
|
const worker = new Worker(new URL("worker.ts", import.meta.url), { type: "module" });
|
||||||
worker.postMessage([zjs.memory, instance, stdin, wasmModule, files]);
|
worker.postMessage([zjs.memory, instance, stdin, wasmModule, files, pid++]);
|
||||||
worker.onmessage = (event) => {
|
worker.onmessage = (event) => {
|
||||||
const [instance] = event.data;
|
const [instance] = event.data;
|
||||||
spawnWorker(instance);
|
spawnWorker(instance);
|
||||||
|
@ -2,7 +2,7 @@ import { importObject, setFiles, setMainThread, setStdin, zjs } from "./imports"
|
|||||||
|
|
||||||
onmessage = async (e) => {
|
onmessage = async (e) => {
|
||||||
console.log("module received from main thread");
|
console.log("module received from main thread");
|
||||||
const [memory, instance, stdin, wasmModule, files] = e.data;
|
const [memory, instance, stdin, wasmModule, files, pid] = e.data;
|
||||||
console.log(wasmModule)
|
console.log(wasmModule)
|
||||||
setStdin(stdin);
|
setStdin(stdin);
|
||||||
setMainThread(false);
|
setMainThread(false);
|
||||||
@ -10,5 +10,5 @@ onmessage = async (e) => {
|
|||||||
importObject.env.memory = memory;
|
importObject.env.memory = memory;
|
||||||
const results = await WebAssembly.instantiate(wasmModule, importObject);
|
const results = await WebAssembly.instantiate(wasmModule, importObject);
|
||||||
zjs.memory = memory;
|
zjs.memory = memory;
|
||||||
results.exports.wasi_thread_start(100, instance);
|
results.exports.wasi_thread_start(pid, instance);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user