code wiki / _hdl_build / nx_dispatch_lease.nx
nx_dispatch_lease.nx
buildroot/runtime/_hdl_build/nx_dispatch_lease.nx
about
nx_dispatch_lease.nx -- WMS rung M4: the LEASING DISPATCHER / SCHEDULER.
module: nishi-core.autonomy.dispatch_lease
capability: DISPATCH_LEASE_NEXT_READY_RUNG (frontier-aware pick + O_EXCL lease)
WHAT THIS ADDS (the missing capability): nx_assign_next/an_pick are READ-ONLY --
they NAME the next runnable rung but never CLAIM it, so two parallel workers both
see the same "next" and collide on one stream. M4 LEASES the pick under an
O_CREAT|O_EXCL lockfile (the kernel guarantees exactly one creator wins -- no
TOCTOU), so exactly one owner holds a given stream at a time. Generalizes the
conductor's single-arc drill into "keep the WHOLE machine moving": if the top
pick is already leased, the dispatcher scans down the w-ordering and leases the
NEXT ready stream instead of stalling.
REUSE / lineage (compose, do not reinvent):
- an_load / an_pick / an_deps_done / an_id_at / an_find <- nx_assign_core (the
dep-graph + readiness + frontier-aware pick are ALREADY correct there)
- O_EXCL acquire/steal lock <- the rt_lock idiom from nx_registry_lock (INLINED
here as dl_lock/dl_unlock so this file keeps a SINGLE nx_syscalls surface and
dodges the double-import rc=6 trap -- nx_assign_core already pulls nx_syscalls
transitively, importing nx_registry_lock too would surface it twice)
- fa_cat / fa_catn / fa_appendz <- nx_framed_append (every status write is ONE
buffer -> ONE locked atomic fa_appendz; the torn-line bug we must NOT reintroduce)
IMPORT DISCIPLINE: import nx_assign_core (surfaces nx_syscalls) + nx_framed_append
(also needs nx_syscalls). The prepass dedups nx_syscalls across imports (proven:
nx_assign_next imports BOTH nx_syscalls AND nx_assign_core and builds clean). We do
NOT import nx_registry_lock (its O_EXCL logic is inlined) -> only two import edges.
license_tier: ORIGINAL
dependencies 2 imports · 3 importers
imports: nx_assign_core.nxnx_framed_append.nx
imported by: nx_dispatch_lease_gate.nxnx_supervised_dispatch.nxnx_supervised_dispatch_tamper.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 32 | const DL_MAGIC_4096: i64 = 4096 |
| 34 | const DL_OEXCL: i64 = 193 // O_CREAT(0x40)|O_EXCL(0x80)|O_WRONLY(0x1) |
| 35 | const DL_MODE: i64 = 420 // 0644 |
| 36 | const DL_STALE_SEC: i64 = 30 // steal a lease whose stamped epoch is older than this (crashed holder) |
| 37 | const DL_REC_CAP: i64 = 256 // bounded status record size (no magic number) |
| 38 | const DL_IDCAP: i64 = 32 // mirrors AN_IDCAP -- max business-key length |
functions
| 41 | func dl_streq(a: *u8, b: *u8) -> i64 |
| 53 | func dl_lease_path(dir: *u8, id: *u8, out: *u8) -> *u8 |
| 72 | func dl_writeint_fd(fd: i64, v: i64) -> i64 called by 1: dl_lock |
| 84 | func dl_readint(path: *u8) -> i64 |
| 95 | func dl_unlink(path: *u8) -> i64 { return __syscall(263, AT_FDCWD, path as i64, 0, 0, 0, 0) } |
| 102 | func dl_lock(lockpath: *u8) -> i64 |
| 119 | func dl_unlock(lockpath: *u8, fd: i64) -> i64 { sys_close(fd); dl_unlink(lockpath); return 0 } |
| 124 | func dl_ready(cx: *i64, r: i64) -> i64 |
| 132 | func dl_pick_ready(cx: *i64) -> i64 |
| 138 | func dl_try_lease(dir: *u8, id: *u8) -> i64 |
| 145 | func dl_release(dir: *u8, id: *u8, fd: i64) -> i64 |
| 153 | func dl_lease_held(dir: *u8, id: *u8) -> i64 |
| 171 | func dl_dispatch(cx: *i64, dir: *u8, id_out: *u8, fd_out: *i64) -> i64 |
| 225 | func dl_emit(path: *u8, verb: *u8, id: *u8, epoch: i64, ok: i64) -> i64 |
| 239 | func dl_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } called by 1: main |
| 246 | func main(argc: i64, argv: *i64) -> i64 |