@ai-ecoverse/slicc-kernel 1.134.4 → 1.135.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.js CHANGED
@@ -7467,7 +7467,7 @@ function satisfies(version, range2) {
7467
7467
  }
7468
7468
 
7469
7469
  // src/version.ts
7470
- var KERNEL_VERSION = true ? "1.134.4" : "0.0.0-dev";
7470
+ var KERNEL_VERSION = true ? "1.135.0" : "0.0.0-dev";
7471
7471
  var OS_RELEASE = "6.0.0-slicc";
7472
7472
  function procVersion() {
7473
7473
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -22952,23 +22952,55 @@ var JsThreads = class {
22952
22952
  get size() {
22953
22953
  return this.live.size;
22954
22954
  }
22955
+ pending = 0;
22956
+ get admission() {
22957
+ return this.deps.admission;
22958
+ }
22955
22959
  spawn(msg) {
22956
- const { control, port } = msg;
22957
- if (this.closed || this.live.size >= this.deps.cap) {
22958
- answer(
22959
- control,
22960
+ if (this.closed || this.live.size + this.pending >= this.deps.cap) {
22961
+ this.refuse(
22962
+ msg,
22960
22963
  this.closed ? { errno: "ESRCH", message: "the process is ending" } : { errno: "EAGAIN", message: `more than ${this.deps.cap} threads` }
22961
22964
  );
22962
- control.close();
22963
- port.close();
22964
22965
  return;
22965
22966
  }
22967
+ this.pending++;
22968
+ this.admission.admit().then(
22969
+ () => {
22970
+ this.pending--;
22971
+ if (!this.closed) {
22972
+ let worker;
22973
+ try {
22974
+ worker = this.deps.createWorker();
22975
+ } catch {
22976
+ this.admission.ended();
22977
+ this.refuse(msg, { errno: "EAGAIN", message: "no worker for the thread" });
22978
+ return;
22979
+ }
22980
+ this.begin(msg, worker);
22981
+ return;
22982
+ }
22983
+ this.admission.ended();
22984
+ this.refuse(msg, { errno: "ESRCH", message: "the process is ending" });
22985
+ },
22986
+ () => {
22987
+ this.pending--;
22988
+ this.refuse(msg, { errno: "EAGAIN", message: "no room for another worker" });
22989
+ }
22990
+ );
22991
+ }
22992
+ refuse(msg, why) {
22993
+ answer(msg.control, why);
22994
+ msg.control.close();
22995
+ msg.port.close();
22996
+ }
22997
+ begin(msg, worker) {
22998
+ const { control, port } = msg;
22966
22999
  const tid = ++this.last;
22967
23000
  const sab = new SharedArrayBuffer(SAB_HEADER_BYTES + SAB_DEFAULT_WINDOW_BYTES);
22968
23001
  const header4 = new Int32Array(sab, 0, SAB_HEADER_I32);
22969
23002
  const owned4 = new SharedArrayBuffer(4 * (1 + JS_THREAD_OWNED_FDS));
22970
23003
  if (this.frozen) Atomics.store(header4, SAB_I_STOP, 1);
22971
- const worker = this.deps.createWorker();
22972
23004
  const clock = this.deps.clocks.thread(tid + 1, sab);
22973
23005
  let ended = false;
22974
23006
  const end = (code) => {
@@ -22987,6 +23019,7 @@ var JsThreads = class {
22987
23019
  responder.dispose();
22988
23020
  lane.dispose();
22989
23021
  this.deps.clocks.threadEnded(tid + 1);
23022
+ this.admission.ended();
22990
23023
  worker.terminate();
22991
23024
  for (const fd of ownedFds(owned4)) {
22992
23025
  void this.deps.dispatch({ op: "fd-close", fd });
@@ -23038,6 +23071,7 @@ var JsThreads = class {
23038
23071
  end(JS_THREAD_CRASHED);
23039
23072
  return;
23040
23073
  }
23074
+ this.admission.started();
23041
23075
  answer(control, { tid });
23042
23076
  }
23043
23077
  crashed(message3, end) {
@@ -23532,7 +23566,8 @@ function jsThreadsOf(opts, process2, token, dispatch2, clocks, header4) {
23532
23566
  openLane: (laneDispatch) => openLane(token, laneDispatch),
23533
23567
  attach: (worker, sab, threadDispatch) => attachSyncSabResponder(worker, sab, token, { dispatch: threadDispatch }),
23534
23568
  dispatch: dispatch2,
23535
- clocks
23569
+ clocks,
23570
+ admission: opts.admission
23536
23571
  });
23537
23572
  process2.onState((state) => threads.stopped(state === "stopped"));
23538
23573
  return threads;
@@ -28002,7 +28037,6 @@ var Launcher = class {
28002
28037
  if (req.links !== void 0) this.links.set(pid, req.links);
28003
28038
  }
28004
28039
  async admitted(wasm, fds, start2) {
28005
- if (!wasm) return start2(fds);
28006
28040
  for (; ; ) {
28007
28041
  await this.memories.admit().catch(async (err) => {
28008
28042
  await fds.closeAll();
@@ -28013,7 +28047,7 @@ var Launcher = class {
28013
28047
  void Promise.resolve(handle2.ready).then(() => this.memories.started());
28014
28048
  return handle2;
28015
28049
  };
28016
- if (!this.memories.near()) {
28050
+ if (!wasm || !this.memories.near()) {
28017
28051
  try {
28018
28052
  return counted3(start2(fds));
28019
28053
  } catch (err) {
@@ -28091,6 +28125,7 @@ var Launcher = class {
28091
28125
  noLinks: stack.noLinks,
28092
28126
  ...this.prefixes.length > 0 && !stack.writer ? { readonlyAt: (path) => isProtected(this.prefixes, path) } : {},
28093
28127
  createWorker: this.createWorker,
28128
+ admission: this.memories,
28094
28129
  onError: req.report,
28095
28130
  onOom: () => {
28096
28131
  this.memories.learn();