From a77f6401a7c0baed78c84bd1b606ab394dd3f4a2 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 26 Nov 2018 02:52:53 -0500 Subject: [PATCH] updates %behn to use effects instead of u3v_keep polling --- include/c/motes.h | 1 + include/vere/vere.h | 9 +++++++++ vere/behn.c | 45 ++++++++++++++++++++++++++++----------------- vere/loop.c | 1 + vere/reck.c | 20 ++++++++++++++++++++ vere/sist.c | 3 +++ 6 files changed, 62 insertions(+), 17 deletions(-) diff --git a/include/c/motes.h b/include/c/motes.h index d8866557d3..f05f716bab 100644 --- a/include/c/motes.h +++ b/include/c/motes.h @@ -325,6 +325,7 @@ # define c3__dorn c3_s4('d','o','r','n') # define c3__dost c3_s4('d','o','s','t') # define c3__dot c3_s3('d','o','t') +# define c3__doze c3_s4('d','o','z','e') # define c3__drag c3_s4('d','r','a','g') # define c3__draz c3_s4('d','r','a','z') # define c3__drib c3_s4('d','r','i','b') diff --git a/include/vere/vere.h b/include/vere/vere.h index 70a22d5e64..83fc4a83c7 100644 --- a/include/vere/vere.h +++ b/include/vere/vere.h @@ -1061,6 +1061,15 @@ void u2_behn_io_poll(void); + /* u3_behn_ef_bake(): notify %behn that we're live + */ + void + u3_behn_ef_bake(void); + + /* u3_behn_ef_doze(): set or cancel timer + */ + void + u3_behn_ef_doze(u3_noun wen); /** HTTP server. **/ diff --git a/vere/behn.c b/vere/behn.c index 04d1989a27..9c6ec613db 100644 --- a/vere/behn.c +++ b/vere/behn.c @@ -45,6 +45,9 @@ static void _behn_time_cb(uv_timer_t* tim_u) { u3_behn* teh_u = &u3_Host.teh_u; + + // XX remove timer backoff + // if(teh_u->run_w < 1024) { teh_u->run_w++; } @@ -62,34 +65,42 @@ _behn_time_cb(uv_timer_t* tim_u) */ void u3_behn_io_poll(void) +{ +} + +/* u3_behn_ef_doze(): set or cancel timer +*/ +void +u3_behn_ef_doze(u3_noun wen) { u3_behn* teh_u = &u3_Host.teh_u; - u3_noun wen = u3v_keep(u3nt(u3_blip, c3__behn, u3_nul)); + + if ( c3y == teh_u->alm ) { + uv_timer_stop(&teh_u->tim_u); + teh_u->alm = c3n; + } if ( (u3_nul != wen) && (c3y == u3du(wen)) && (c3y == u3ud(u3t(wen))) ) { c3_d gap_d = u3_time_gap_ms(u3k(u3A->now), u3k(u3t(wen))); - -#if 0 - fprintf(stderr, "gap_d %llu, plus %llu\r\n", - gap_d, gap_d + (c3_d)teh_u->run_w); -#endif + // XX remove timer backoff + // gap_d += teh_u->run_w; - if ( c3y == teh_u->alm ) { - uv_timer_stop(&teh_u->tim_u); - } - else teh_u->alm = c3y; - uv_timer_start(&teh_u->tim_u, _behn_time_cb, gap_d, 0); } - else { - if ( c3y == teh_u->alm ) { - uv_timer_stop(&teh_u->tim_u); - } - teh_u->alm = c3n; - } + u3z(wen); } + +/* u3_behn_ef_bake(): notify %behn that we're live +*/ +void +u3_behn_ef_bake(void) +{ + u3_noun pax = u3nq(u3_blip, c3__behn, u3k(u3A->sen), u3_nul); + + u3v_plan(pax, u3nc(c3__born, u3_nul)); +} diff --git a/vere/loop.c b/vere/loop.c index 130ee87fa2..8f6435d20a 100644 --- a/vere/loop.c +++ b/vere/loop.c @@ -669,6 +669,7 @@ u3_lo_lead(void) { if ( c3n == u3_Host.ops_u.nuu ) { u3_ames_ef_bake(); + u3_behn_ef_bake(); } u3_http_ef_bake(); diff --git a/vere/reck.c b/vere/reck.c index 28dba19884..4a47270810 100644 --- a/vere/reck.c +++ b/vere/reck.c @@ -166,6 +166,22 @@ _reck_kick_http(u3_noun pox, c3_assert(!"not reached"); return c3n; } +/* _reck_kick_behn(): apply packet network outputs. +*/ +static u3_noun +_reck_kick_behn(u3_noun pox, u3_noun fav) +{ + switch ( u3h(fav) ) { + default: break; + + case c3__doze: { + u3_behn_ef_doze(u3k(u3t(fav))); + u3z(pox); u3z(fav); return c3y; + } break; + } + u3z(pox); u3z(fav); return c3n; +} + /* _reck_kick_sync(): apply sync outputs. */ static u3_noun @@ -277,6 +293,10 @@ _reck_kick_spec(u3_noun pox, u3_noun fav) return _reck_kick_http(pox, sev_l, coq_l, seq_l, fav); } break; + case c3__behn: { + return _reck_kick_behn(pox, fav); + } break; + case c3__clay: case c3__boat: case c3__sync: { diff --git a/vere/sist.c b/vere/sist.c index 6116f51518..a03fdcfa3d 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -1687,6 +1687,9 @@ u3_sist_boot(void) u3_ames_ef_bake(); } + // initialize %behn + u3_behn_ef_bake(); + // Authenticate and initialize terminal. u3_term_ef_bake(pig);