code wiki / _hdl_build / nx_arbiter.nx

nx_arbiter.nx

buildroot/runtime/_hdl_build/nx_arbiter.nx

3290 B63 linesdepth 2pulls 2 transitivereach 135 importersview sourcekind librarytopic arbiter
docsdependenciesstructsconstsfunctions

about

nx_arbiter.nx -- ARBITRATION primitive for conflict-free PARALLEL workstreams (pillar 3 of the orchestration fix). Some sinks CANNOT be isolated -- they are inherently shared: the NAS push target (one wiki doc-root), _offc/ installs, the memory files (a sibling clobbered MEMORY.md + genesis_lineage.tsv mid-write today), the WMS queue, the git repo. For those, serialize concurrent writers with a KERNEL-ENFORCED advisory lock (flock) keyed by a named resource. A workstream takes the lock, does its critical write, releases; siblings contending on the SAME resource wait their turn. Uses sys_flock (nx_syscalls.nx, the RV64-32 -> x86_64-73 wrapper) -- NOT raw __syscall(73): the compiler translates rv64 numbers, so the x86_64 number passed raw lands on the WRONG syscall (proven: raw 73 -> EFAULT). Imports ONLY nx_syscalls.nx (NOT the legacy nx_flock.nx organ) to avoid the double-import rc=6 trap. fl_try(resource) -> fd>=0 if acquired now, -1 if busy/err (non-blocking). fl_acquire(resource, tries, ms) -> fd>=0 (bounded wait), -1 on timeout. fl_release(fd) -> unlock + close. Lock files: /home/.../.nishi/locks/<resource>.lock (shared BY DESIGN = the rendezvous point). license_tier: ORIGINAL

dependencies 1 imports · 15 importers

nx_syscalls.nx nx_arbiter.nx nx_arbiter_gate.nx nx_arbiter_race_gate.nx nx_arbiter_serve.nx nx_aw_hostctl.nx nx_aw_send.nx nx_doctor_apply.nx nx_doctor_queue.nx nx_pm_sclass_loop.nx nx_pub_recover.nx nx_pub_ship.nx

diagram shows first 10 each side; +0 more imports, +5 more importers in the complete lists below.

imports: nx_syscalls.nx

imported by: nx_arbiter_gate.nxnx_arbiter_race_gate.nxnx_arbiter_serve.nxnx_aw_hostctl.nxnx_aw_send.nxnx_doctor_apply.nxnx_doctor_queue.nxnx_pm_sclass_loop.nxnx_pub_recover.nxnx_pub_ship.nxnx_publisher.nxnx_release_master.nxnx_role_queue.nxnx_sclass_dispatch_gate.nxnx_synced_push.nx

structs

none

consts

16const FL_MAGIC_1000000: i64 = 1000000
18const FL_LOCKDIR: *u8 = "/home/elderwesto/.nishi/locks"
19const FL_EXNB: i64 = 6 // SYS_LOCK_EX(2) | SYS_LOCK_NB(4)
20const FL_UN: i64 = 8 // SYS_LOCK_UN

functions

22func fl_mkdir() -> i64 { let ld: *u8 = FL_LOCKDIR; __syscall(83, ld as i64, 448, 0, 0, 0, 0); return 0 }
called by 1: fl_try
23func fl_nap(ms: i64) -> i64 { let ts: *i64 = sys_mmap(16) as *i64; ts[0] = 0; ts[1] = ms * FL_MAGIC_1000000; __syscall(35, ts as i64, 0, 0, 0, 0, 0); return 0 }
called by 1: fl_acquire calls 1: sys_mmap
26func fl_path(resource: *u8, out: *u8) -> i64
called by 2: fl_trymain
38func fl_try(resource: *u8) -> i64
48func fl_acquire(resource: *u8, tries: i64, nap_ms: i64) -> i64
60func fl_release(fd: i64) -> i64