From: ian Date: Tue, 8 Apr 2008 20:55:35 +0000 (+0000) Subject: wip new hostside (realtime) before big merge X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=d0945ef030cff32dd4ca3f364e16eafa485cd819;p=trains.git wip new hostside (realtime) before big merge --- diff --git a/hostside/actual.c b/hostside/actual.c index 21eef04..c371b13 100644 --- a/hostside/actual.c +++ b/hostside/actual.c @@ -29,7 +29,10 @@ int picinsn_polarity_testbit(const PicInsn *pi, const SegmentInfo *segi) { } void actual_inversions_start(void) { + int i; polarityinsn.l= (info_maxreverse + 4 + 6) / 7; + for (i=1; iout); events->on_fd(events, readfd, OOP_EXCEPTION, cmdi_exception, cmdi); diff --git a/hostside/daemons.h b/hostside/daemons.h index 0db7963..2fd57d4 100644 --- a/hostside/daemons.h +++ b/hostside/daemons.h @@ -26,9 +26,10 @@ struct OutBufferChain { /* set by user: */ char *desc; int fd; + int limit; /* 0 means obc_init will set a default */ OutBufferError *error; /* set/used by obc_..., oprintf, etc., only */ - int done_of_head; + int done_of_head, total; struct { OutBuffer *head, *tail; } obs; }; diff --git a/hostside/obc.c b/hostside/obc.c index 040ee6a..33ab3f2 100644 --- a/hostside/obc.c +++ b/hostside/obc.c @@ -30,8 +30,8 @@ int obc_tryflush(OutBufferChain *ch) { } if (ch->done_of_head == ob->l) { LIST_UNLINK(ch->obs, ob); - free(ob); free(ob->m); + free(ob); ch->done_of_head= 0; continue; } @@ -44,6 +44,7 @@ int obc_tryflush(OutBufferChain *ch) { } assert(r>=0); ch->done_of_head += r; + ch->total -= r; assert(ch->done_of_head <= ob->l); } } @@ -61,11 +62,21 @@ static void addlink(OutBufferChain *ch, OutBuffer *ob) { if (!ch->obs.head) events->on_fd(events, ch->fd, OOP_WRITE, writeable, ch); LIST_LINK_TAIL(ch->obs, ob); + ch->total += ob->l; + obc_tryflush(ch); + if (ch->total > ch->limit) { + char what[128]; + snprintf(what,sizeof(what)-1,"`%.*s...'", ob->l,ob->m); + what[sizeof(what)-1]= 0; + ch->error(ch,"buffer limit exceeded",what); + } } void obc_init(OutBufferChain *ch) { int r; ch->done_of_head= 0; + ch->total= 0; + if (!ch->limit) ch->limit= 128*1024; r= oop_fd_nonblock(ch->fd, 1); if (r) diee("nonblock(OutBufferChain->fd,1)"); LIST_INIT(ch->obs); diff --git a/hostside/persist.c b/hostside/persist.c index e7faccf..13eff37 100644 --- a/hostside/persist.c +++ b/hostside/persist.c @@ -46,7 +46,7 @@ #include "realtime.h" const char *persist_fn= "persist"; -const char *persist_record_converted; +char *persist_record_converted; static int fd= -1; static void *mapbase; @@ -155,7 +155,8 @@ void persist_entrails_interpret(void) { try(FN1(data), FN1(conv)) || try(FN(data,old), FN(conv,old)) || try(FN1(data), FN(conv,old)) || - (persist_record_converted= 0); + (free(persist_record_converted), + persist_record_converted=0); } /*---------- stupid mmap workaround ----------*/ diff --git a/hostside/realtime.c b/hostside/realtime.c index 99544ce..ae2082b 100644 --- a/hostside/realtime.c +++ b/hostside/realtime.c @@ -232,7 +232,10 @@ void vbadcmd(ParseState *ps, const char *fmt, va_list al) { } static void obc_error(OutBufferChain *ch, const char *e1, const char *e2) { - comms_error(ch->desc, e1, e2); + if (!e1) { assert(!e2); exit(0); } + fprintf(stderr,"command communication error: %s%s%s\n", + e1, e2?": ":"", e2?e2:""); + exit(-1); } void ouhex(const char *word, const Byte *command, int length) { diff --git a/hostside/realtime.h b/hostside/realtime.h index ca5e101..c5c1526 100644 --- a/hostside/realtime.h +++ b/hostside/realtime.h @@ -101,7 +101,7 @@ void persist_entrails_run_converter(void); void persist_install(void); extern const char *persist_fn; -extern const char *persist_record_converted; +extern char *persist_record_converted; void persist_map_veryearly(void); diff --git a/hostside/resolve.c b/hostside/resolve.c index 2dfc6a6..317f9ac 100644 --- a/hostside/resolve.c +++ b/hostside/resolve.c @@ -153,8 +153,10 @@ void resolve_begin(void) { FOR_SEG { seg->res_detect= 0; seg->tr_updated= 0; - seg->seg_inverted &= segi->invertible; - actual_inversions_segment(seg); + if (segi->invertible) + actual_inversions_segment(seg); + else + seg->seg_inverted= 0; } actual_inversions_done(); } @@ -202,7 +204,6 @@ int resolve_complete(void) { /* 3. we have a violation of D \subset U, namely d */ oprintf(UPO, "resolving violation @%s\n", di->pname); - nextphase= 0; if (d->owner) { /* 3a perhaps */ oprintf(UPO, "resolving expected %s\n", t->pname); @@ -237,6 +238,7 @@ int resolve_complete(void) { /* Yay! 3a. */ t->resolution= RR_E; + nextphase= 0; already_3a: oprintf(UPO, "resolving supposing %s as-expected\n", t->pname); continue; @@ -255,6 +257,7 @@ int resolve_complete(void) { if (tplus->resolution == RR_E) { oprintf(UPO, "resolving supposing %s absent\n", tplus->pname); tplus->resolution= RR_N; + nextphase= 0; } } /* Now must trim U to correspond to our setting of R(t+)=N @@ -266,6 +269,7 @@ int resolve_complete(void) { } t1->resolution= RR_H; + nextphase= 0; oprintf(UPO, "resolving supposing %s at-home\n", t1->pname); continue; diff --git a/hostside/safety.h b/hostside/safety.h index 95d4e27..8e6d0e5 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -260,7 +260,7 @@ const SegmentLinkInfo *trackloc_segmentlink(const TrackLocation *tloc, #define FOR_SEGMENT(seg, initx, stepx) \ for (seg##n=0, seg=segments, seg##i=info_segments; \ - seg##n <= NUM_SEGMENTS; \ + seg##n < NUM_SEGMENTS; \ seg##n++, seg++, seg##i++, stepx) #define FOR_TRAIN(tra, initx, stepx) \ diff --git a/layout/layout-data.h b/layout/layout-data.h index 4bb569a..d5900b3 100644 --- a/layout/layout-data.h +++ b/layout/layout-data.h @@ -25,6 +25,7 @@ typedef int Distance; typedef enum { mfk_none, mfk_point + /* must also add new entries to movpos.c:methodinfos */ } MovFeatKind; /*========== data from config files and layout cad/cam ==========*/ @@ -69,7 +70,7 @@ extern const SegmentInfo info_segments[]; extern const BoardObject info_maxreverse; /* max. reverse + 1 */ -#define NOTA(x) (-1) +#define NOTA(thing) (-1) #define SOMEP(x) ((x) >= 0) #endif /*LAYOUT_DATA_H*/