@ai-ecoverse/slicc-kernel 1.17.1 → 1.17.2

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.
@@ -3358,20 +3358,20 @@ function pathInode(path) {
3358
3358
  }
3359
3359
  return h;
3360
3360
  }
3361
- function cachingBridge(bridge) {
3361
+ function cachingBridge(bridge, now = () => performance.now()) {
3362
3362
  const stats = /* @__PURE__ */ new Map();
3363
3363
  const lstats = /* @__PURE__ */ new Map();
3364
3364
  const cached = (map, path, get) => {
3365
3365
  let hit = map.get(path);
3366
- if (hit === void 0) {
3366
+ if (hit === void 0 || "until" in hit && hit.until <= now()) {
3367
3367
  try {
3368
3368
  hit = get();
3369
3369
  } catch (e) {
3370
- hit = e;
3370
+ hit = { error: e, until: now() + MISS_TTL_MS };
3371
3371
  }
3372
3372
  map.set(path, hit);
3373
3373
  }
3374
- if (hit instanceof Error) throw hit;
3374
+ if ("until" in hit) throw hit.error;
3375
3375
  return hit;
3376
3376
  };
3377
3377
  const invalidate = () => {
@@ -3421,7 +3421,7 @@ function cachingBridge(bridge) {
3421
3421
  invalidate
3422
3422
  };
3423
3423
  }
3424
- var WasiError, FileBuffer, LocalFile;
3424
+ var WasiError, FileBuffer, LocalFile, MISS_TTL_MS;
3425
3425
  var init_wasi_files = __esm({
3426
3426
  "src/process/wasi/wasi-files.ts"() {
3427
3427
  "use strict";
@@ -3550,6 +3550,7 @@ var init_wasi_files = __esm({
3550
3550
  this.buffer.flush();
3551
3551
  }
3552
3552
  };
3553
+ MISS_TTL_MS = 20;
3553
3554
  }
3554
3555
  });
3555
3556
 
@@ -4312,27 +4313,30 @@ function pollOneoff(deps, inPtr, outPtr, nsubs, neventsPtr) {
4312
4313
  const subs = readSubscriptions(mem, inPtr, nsubs, deps.now);
4313
4314
  const { events, read, write } = classify(deps.fds, subs);
4314
4315
  let interrupted = false;
4316
+ const earliest = subs.reduce((min, s) => Math.min(min, s.deadline), Infinity);
4317
+ const expired = () => performance.now() + CLOCK_SLACK_MS >= earliest;
4315
4318
  if (read.length > 0 || write.length > 0 || events.length === 0) {
4316
- const earliest = Math.min(...subs.map((s) => s.deadline));
4317
- let timeoutMs = -1;
4318
- if (events.length > 0) timeoutMs = 0;
4319
- else if (earliest !== Infinity)
4320
- timeoutMs = Math.max(0, Math.ceil(earliest - performance.now()));
4321
- let ready;
4322
- try {
4323
- ready = kernel.call({ op: "fd-select", read, write, timeoutMs });
4324
- } catch (e) {
4325
- if (!deps.interruptWakes || e.code !== "EINTR") throw e;
4326
- interrupted = true;
4327
- ready = { read: [], write: [] };
4328
- }
4329
- events.push(
4330
- ...readyEvents(subs, ready)
4331
- );
4319
+ do {
4320
+ let timeoutMs = -1;
4321
+ if (events.length > 0) timeoutMs = 0;
4322
+ else if (earliest !== Infinity)
4323
+ timeoutMs = Math.max(0, Math.ceil(earliest - performance.now()));
4324
+ let ready;
4325
+ try {
4326
+ ready = kernel.call({ op: "fd-select", read, write, timeoutMs });
4327
+ } catch (e) {
4328
+ if (!deps.interruptWakes || e.code !== "EINTR") throw e;
4329
+ interrupted = true;
4330
+ ready = { read: [], write: [] };
4331
+ }
4332
+ events.push(
4333
+ ...readyEvents(subs, ready)
4334
+ );
4335
+ } while (events.length === 0 && !interrupted && earliest !== Infinity && !expired());
4332
4336
  }
4333
4337
  const after = performance.now();
4334
4338
  for (const s of subs) {
4335
- if (s.type === EVENTTYPE.CLOCK && (interrupted || s.deadline <= after + 0.5)) {
4339
+ if (s.type === EVENTTYPE.CLOCK && (interrupted || s.deadline <= after + CLOCK_SLACK_MS)) {
4336
4340
  events.push({ userdata: s.userdata, error: E.SUCCESS, type: s.type });
4337
4341
  }
4338
4342
  }
@@ -4340,10 +4344,12 @@ function pollOneoff(deps, inPtr, outPtr, nsubs, neventsPtr) {
4340
4344
  mem.view().setUint32(neventsPtr, events.length, true);
4341
4345
  return E.SUCCESS;
4342
4346
  }
4347
+ var CLOCK_SLACK_MS;
4343
4348
  var init_wasi_poll = __esm({
4344
4349
  "src/process/wasi/wasi-poll.ts"() {
4345
4350
  "use strict";
4346
4351
  init_wasi_abi();
4352
+ CLOCK_SLACK_MS = 0.5;
4347
4353
  }
4348
4354
  });
4349
4355
 
@@ -4471,19 +4477,25 @@ var init_wasi_host = __esm({
4471
4477
  ...this.statImports(),
4472
4478
  ...this.pathImports(),
4473
4479
  ...this.socketImports(),
4474
- poll_oneoff: (inPtr, outPtr, n, nevents) => pollOneoff(
4475
- {
4476
- mem: this.mem,
4477
- fds: this.fds,
4478
- kernel: this.o.kernel,
4479
- now: (id) => this.now(id),
4480
- interruptWakes: this.interruptWakes
4481
- },
4482
- inPtr,
4483
- outPtr,
4484
- n,
4485
- nevents
4486
- )
4480
+ poll_oneoff: (inPtr, outPtr, n, nevents) => {
4481
+ try {
4482
+ return pollOneoff(
4483
+ {
4484
+ mem: this.mem,
4485
+ fds: this.fds,
4486
+ kernel: this.o.kernel,
4487
+ now: (id) => this.now(id),
4488
+ interruptWakes: this.interruptWakes
4489
+ },
4490
+ inPtr,
4491
+ outPtr,
4492
+ n,
4493
+ nevents
4494
+ );
4495
+ } finally {
4496
+ this.o.fs.invalidate?.();
4497
+ }
4498
+ }
4487
4499
  });
4488
4500
  return this.cache;
4489
4501
  }