code wiki / _hdl_build / nx_dispatch_lease.nx

nx_dispatch_lease.nx

buildroot/runtime/_hdl_build/nx_dispatch_lease.nx

12253 B273 linesdepth 3pulls 4 transitivereach 5 importersview sourcekind tooltopic dispatch
docsdependenciesstructsconstsfunctions

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

nx_assign_core.nx nx_framed_append.nx nx_dispatch_lease.nx nx_dispatch_lease_gate.nx nx_supervised_dispatch.nx nx_supervised_dispatch_tamper.nx

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

main sys_mkdir an_newcx sys_mmap an_load sys_mmap ↻ sys_openat_rd sys_read sys_close an_id_at an_deps_at an_gate_at an_title_at dl_p dl_dispatch dl_pick_ready an_pick an_deps_done an_deps_at ↻ sys_mmap ↻ an_find an_streq an_id_at ↻ an_id_at ↻ dl_try_lease dl_lease_path dl_lock dl_writeint_fd sys_now_realtime_sec sys_mmap ↻ sys_clock_gettime_real dl_readint sys_read ↻ dl_unlink dl_ready an_deps_done ↻ dl_lease_held dl_lease_path ↻ dl_emit fa_cat

structs

none

consts

32const DL_MAGIC_4096: i64 = 4096
34const DL_OEXCL: i64 = 193 // O_CREAT(0x40)|O_EXCL(0x80)|O_WRONLY(0x1)
35const DL_MODE: i64 = 420 // 0644
36const DL_STALE_SEC: i64 = 30 // steal a lease whose stamped epoch is older than this (crashed holder)
37const DL_REC_CAP: i64 = 256 // bounded status record size (no magic number)
38const DL_IDCAP: i64 = 32 // mirrors AN_IDCAP -- max business-key length

functions

41func dl_streq(a: *u8, b: *u8) -> i64
called by 3: mainmainmain
53func dl_lease_path(dir: *u8, id: *u8, out: *u8) -> *u8
72func dl_writeint_fd(fd: i64, v: i64) -> i64
called by 1: dl_lock
84func dl_readint(path: *u8) -> i64
called by 1: dl_lock calls 1: sys_read
102func dl_lock(lockpath: *u8) -> i64
119func dl_unlock(lockpath: *u8, fd: i64) -> i64 { sys_close(fd); dl_unlink(lockpath); return 0 }
called by 1: dl_release calls 1: dl_unlink
124func dl_ready(cx: *i64, r: i64) -> i64
called by 2: dl_dispatchmain calls 1: an_deps_done
132func dl_pick_ready(cx: *i64) -> i64
called by 2: dl_dispatchmain calls 1: an_pick
138func dl_try_lease(dir: *u8, id: *u8) -> i64
145func dl_release(dir: *u8, id: *u8, fd: i64) -> i64
153func dl_lease_held(dir: *u8, id: *u8) -> i64
called by 2: dl_dispatchmain calls 1: dl_lease_path
171func dl_dispatch(cx: *i64, dir: *u8, id_out: *u8, fd_out: *i64) -> i64
225func dl_emit(path: *u8, verb: *u8, id: *u8, epoch: i64, ok: i64) -> i64
called by 1: main calls 3: fa_catfa_catnfa_appendz
239func 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
246func main(argc: i64, argv: *i64) -> i64