code wiki / _hdl_build / nx_clockjobs.nx

nx_clockjobs.nx

buildroot/runtime/_hdl_build/nx_clockjobs.nx

13052 B214 linesdepth 5pulls 6 transitivereach 0 importersview sourcekind orphan library
docsdependenciesstructsconstsfunctions

about

nx_clock.nx -- THE ONE NISHI CLOCK (operator: "we should be s class exceed like how pulses work on clocks ... so we avoid issues ... dont have a million pulses and daemons"). Researched (knowledge/fetched/sched_*.raw: clock-distribution = ONE oscillator -> a tree of DIVIDERS; PLL derives every frequency from ONE reference; cron = ONE daemon reads ONE table of timed jobs; tickless = don't burn a constant tick when idle). The S-class pattern is identical: ONE tick source + ONE durable JOB REGISTRY + ONE dispatcher. Every periodic capability REGISTERS a job (name, interval-in-ticks) = a divider off the single clock -- it does NOT spin up its own daemon/pulse loop. So N capabilities cost ONE loop, not N. This library is the registry + dispatcher; the single tick source drives it (one external spark, like a crystal). license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_store_seed_lib.nx nx_clockjobs.nx

imports: nx_syscalls.nxnx_store_seed_lib.nx

imported by: nobody (leaf or entry point)

structs

none

consts

12const CLK_MAXJOBS: i64 = 128
13const CLK_NAMEW: i64 = 48 // bytes per job name slot
14const CLK_REG: *u8 = "knowledge/sched/jobs.tsv" // the ONE durable registry (the "crontab")

functions

16func clk_slot(names: *u8, i: i64) -> *u8 { return ((names as i64) + i*CLK_NAMEW) as *u8 }
17func clk_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 }
called by 1: clk_find
19func clk_find(names: *u8, n: i64, name: *u8) -> i64 { var i: i64=0; while i<n { if clk_streq(clk_slot(names,i), name)==1 { return i } i=i+1 } return 0-1 }
23func clk_register(names: *u8, organs: *u8, intervals: *i64, next_due: *i64, np: *i64, name: *u8, organ: *u8, interval: i64) -> i64
40func clk_tick(intervals: *i64, next_due: *i64, n: i64, now: i64, fired: *i64) -> i64
57func clk_dispatch_run(organs: *u8, intervals: *i64, next_due: *i64, n: i64, now: i64, fired: *i64) -> i64
89func clk_run_tickless(organs: *u8, intervals: *i64, next_due: *i64, n: i64, start_tick: i64, maxbeats: i64, tick_ms: i64, out: *i64) -> i64
112func clk_due_in(next_due_i: i64, now: i64) -> i64 { return next_due_i - now }
113func clk_twin_ok(organ: *u8) -> i64 { let fd: i64 = sys_openat_rd(organ); if fd < 0 { return 0 } sys_close(fd); return 1 }
115func clk_itoa(buf: *u8, o: i64, v: i64) -> i64 { var w: i64=o; var m: i64=v; if m==0{buf[w]=48 as u8;return w+1} if m<0{buf[w]=45 as u8;w=w+1;m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var j:i64=0; while j<k{buf[w]=t[k-1-j];w=w+1;j=j+1} return w }
called by 1: clk_save calls 1: sys_mmap
118func clk_save(path: *u8, names: *u8, organs: *u8, intervals: *i64, next_due: *i64, n: i64) -> i64
141func clk_merge_store(prefix: *u8, names: *u8, organs: *u8, intervals: *i64, next_due: *i64, np: *i64, base_tick: i64) -> i64
181func clk_load(path: *u8, names: *u8, organs: *u8, intervals: *i64, next_due: *i64, np: *i64) -> i64