mirror of
https://github.com/urbit/shrub.git
synced 2024-12-20 09:21:42 +03:00
vere: adds common structure management in ward.c
This commit is contained in:
parent
8497cd65c6
commit
df7cd2a673
@ -683,6 +683,28 @@
|
||||
c3_d
|
||||
u3_time_gap_ms(u3_noun now, u3_noun wen);
|
||||
|
||||
/** ward: common structure lifecycle
|
||||
**/
|
||||
/* u3_fact_init(): initialize completed event.
|
||||
*/
|
||||
u3_fact*
|
||||
u3_fact_init(c3_d eve_d, c3_l mug_l, u3_noun job);
|
||||
|
||||
/* u3_fact_free(): dispose completed event.
|
||||
*/
|
||||
void
|
||||
u3_fact_free(u3_fact *tac_u);
|
||||
|
||||
/* u3_gift_init(): initialize effect list.
|
||||
*/
|
||||
u3_gift*
|
||||
u3_gift_init(c3_d eve_d, u3_noun act);
|
||||
|
||||
/* u3_gift_free(): dispose effect list.
|
||||
*/
|
||||
void
|
||||
u3_gift_free(u3_gift* gif_u);
|
||||
|
||||
/** New vere
|
||||
**/
|
||||
/* u3_auto_init(): initialize all drivers.
|
||||
|
@ -99,11 +99,10 @@ _disk_commit_done(struct _cd_save* req_u)
|
||||
|
||||
{
|
||||
u3_fact* tac_u = log_u->put_u.ext_u;
|
||||
|
||||
|
||||
while ( tac_u && (tac_u->eve_d <= log_u->dun_d) ) {
|
||||
log_u->put_u.ext_u = tac_u->nex_u;
|
||||
u3z(tac_u->job);
|
||||
c3_free(tac_u);
|
||||
u3_fact_free(tac_u);
|
||||
tac_u = log_u->put_u.ext_u;
|
||||
}
|
||||
}
|
||||
@ -257,21 +256,18 @@ u3_disk_plan(u3_disk* log_u, u3_fact* tac_u)
|
||||
void
|
||||
u3_disk_boot_plan(u3_disk* log_u, u3_noun job)
|
||||
{
|
||||
u3_fact* tac_u = c3_malloc(sizeof(*tac_u));
|
||||
tac_u->mug_l = 0; //u3r_mug(job); XX
|
||||
tac_u->eve_d = ++log_u->sen_d;
|
||||
tac_u->nex_u = 0;
|
||||
tac_u->job = job;
|
||||
// NB, boot mugs are 0
|
||||
//
|
||||
u3_fact* tac_u = u3_fact_init(++log_u->sen_d, 0, job);
|
||||
tac_u->bug_l = 0; // XX
|
||||
|
||||
if ( !log_u->put_u.ent_u ) {
|
||||
c3_assert( !log_u->put_u.ext_u );
|
||||
c3_assert( 1ULL == log_u->sen_d );
|
||||
|
||||
tac_u->bug_l = 0; // XX
|
||||
log_u->put_u.ent_u = log_u->put_u.ext_u = tac_u;
|
||||
}
|
||||
else {
|
||||
tac_u->bug_l = log_u->put_u.ent_u->mug_l; // XX
|
||||
log_u->put_u.ent_u->nex_u = tac_u;
|
||||
log_u->put_u.ent_u = tac_u;
|
||||
}
|
||||
@ -313,26 +309,30 @@ _disk_read_one_cb(void* vod_p, c3_d eve_d, size_t val_i, void* val_p)
|
||||
{
|
||||
struct _cd_read* red_u = vod_p;
|
||||
u3_disk* log_u = red_u->log_u;
|
||||
u3_fact* tac_u = c3_calloc(sizeof(*tac_u));
|
||||
tac_u->eve_d = eve_d;
|
||||
u3_fact* tac_u;
|
||||
|
||||
{
|
||||
// XX u3m_soft?
|
||||
//
|
||||
u3_noun dat = u3ke_cue(u3i_bytes(val_i, val_p));
|
||||
u3_noun mug, job;
|
||||
c3_l bug_l;
|
||||
|
||||
|
||||
if ( (c3n == u3r_cell(dat, &mug, &job))
|
||||
|| (c3n == u3r_safe_word(mug, &tac_u->bug_l)) ) // XX
|
||||
|| (c3n == u3r_safe_word(mug, &bug_l)) ) // XX
|
||||
{
|
||||
// failure here triggers cleanup in _disk_read_start_cb()
|
||||
//
|
||||
c3_free(tac_u);
|
||||
u3z(dat);
|
||||
return c3n;
|
||||
}
|
||||
|
||||
tac_u->job = u3k(job);
|
||||
// NB: mug is unknown due to log format
|
||||
//
|
||||
tac_u = u3_fact_init(eve_d, 0, u3k(job));
|
||||
tac_u->bug_l = bug_l;
|
||||
|
||||
u3z(dat);
|
||||
}
|
||||
|
||||
|
@ -409,17 +409,13 @@ _lord_work_done(u3_lord* god_u,
|
||||
u3_noun job,
|
||||
u3_noun act)
|
||||
{
|
||||
u3_fact* tac_u = c3_malloc(sizeof(*tac_u));
|
||||
tac_u->bug_l = god_u->mug_l;
|
||||
tac_u->mug_l = god_u->mug_l = mug_l;
|
||||
tac_u->eve_d = god_u->eve_d = eve_d;
|
||||
tac_u->nex_u = 0;
|
||||
tac_u->job = job;
|
||||
u3_fact* tac_u = u3_fact_init(eve_d, mug_l, job);
|
||||
tac_u->bug_l = god_u->mug_l; // XX
|
||||
|
||||
u3_gift* gif_u = c3_malloc(sizeof(*gif_u));
|
||||
gif_u->eve_d = eve_d;
|
||||
gif_u->nex_u = 0;
|
||||
gif_u->act = act;
|
||||
god_u->mug_l = mug_l;
|
||||
god_u->eve_d = eve_d;
|
||||
|
||||
u3_gift* gif_u = u3_gift_init(eve_d, act);
|
||||
|
||||
_lord_work_spin(god_u);
|
||||
|
||||
|
@ -131,12 +131,9 @@ _pier_gift_kick(u3_work* wok_u)
|
||||
#ifdef VERBOSE_PIER
|
||||
fprintf(stderr, "pier: (%" PRIu64 "): compute: release\r\n", gif_u->eve_d);
|
||||
#endif
|
||||
u3_auto_kick(wok_u->car_u, gif_u->act);
|
||||
|
||||
// XX dispose properly
|
||||
//
|
||||
u3z(gif_u->act);
|
||||
c3_free(gif_u);
|
||||
u3_auto_kick(wok_u->car_u, gif_u->act);
|
||||
u3_gift_free(gif_u);
|
||||
}
|
||||
}
|
||||
|
||||
@ -644,8 +641,7 @@ _pier_on_lord_play_done(void* vod_p, u3_info fon_u, c3_l mug_l)
|
||||
|
||||
while ( tac_u ) {
|
||||
nex_u = tac_u->nex_u;
|
||||
u3z(tac_u->job);
|
||||
c3_free(tac_u);
|
||||
u3_fact_free(tac_u);
|
||||
tac_u = nex_u;
|
||||
}
|
||||
}
|
||||
@ -673,8 +669,7 @@ _pier_on_lord_play_bail(void* vod_p, u3_info fon_u,
|
||||
while ( tac_u->eve_d < eve_d ) {
|
||||
nex_u = tac_u->nex_u;
|
||||
las_l = tac_u->mug_l;
|
||||
u3z(tac_u->job);
|
||||
c3_free(tac_u);
|
||||
u3_fact_free(tac_u);
|
||||
tac_u = nex_u;
|
||||
}
|
||||
|
||||
|
71
pkg/urbit/vere/ward.c
Normal file
71
pkg/urbit/vere/ward.c
Normal file
@ -0,0 +1,71 @@
|
||||
/* vere/ward.c
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <setjmp.h>
|
||||
#include <gmp.h>
|
||||
#include <sigsegv.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <uv.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "all.h"
|
||||
#include "vere/vere.h"
|
||||
|
||||
// ward: lifecycle management for common structures
|
||||
//
|
||||
// should contain anything allocated in multiple modules,
|
||||
// or allocated in one and freed in another
|
||||
//
|
||||
|
||||
/* u3_fact_init(): initialize completed event.
|
||||
*/
|
||||
u3_fact*
|
||||
u3_fact_init(c3_d eve_d, c3_l mug_l, u3_noun job)
|
||||
{
|
||||
u3_fact *tac_u = c3_malloc(sizeof(*tac_u));
|
||||
tac_u->eve_d = eve_d;
|
||||
tac_u->mug_l = mug_l;
|
||||
tac_u->nex_u = 0;
|
||||
tac_u->job = job;
|
||||
|
||||
return tac_u;
|
||||
}
|
||||
|
||||
/* u3_fact_free(): dispose completed event.
|
||||
*/
|
||||
void
|
||||
u3_fact_free(u3_fact *tac_u)
|
||||
{
|
||||
u3z(tac_u->job);
|
||||
c3_free(tac_u);
|
||||
}
|
||||
|
||||
/* u3_gift_init(): initialize effect list.
|
||||
*/
|
||||
u3_gift*
|
||||
u3_gift_init(c3_d eve_d, u3_noun act)
|
||||
{
|
||||
u3_gift *gif_u = c3_malloc(sizeof(*gif_u));
|
||||
gif_u->eve_d = eve_d;
|
||||
gif_u->nex_u = 0;
|
||||
gif_u->act = act;
|
||||
|
||||
return gif_u;
|
||||
}
|
||||
|
||||
/* u3_gift_free(): dispose effect list.
|
||||
*/
|
||||
void
|
||||
u3_gift_free(u3_gift* gif_u)
|
||||
{
|
||||
u3z(gif_u->act);
|
||||
c3_free(gif_u);
|
||||
}
|
Loading…
Reference in New Issue
Block a user