chiark / gitweb /
wip new hostside (realtime) before big merge branch-hostside-wip-2008-01-25
authorian <ian>
Tue, 8 Apr 2008 20:55:35 +0000 (20:55 +0000)
committerian <ian>
Tue, 8 Apr 2008 20:55:35 +0000 (20:55 +0000)
hostside/actual.c
hostside/cmdinput.c
hostside/daemons.h
hostside/obc.c
hostside/persist.c
hostside/realtime.c
hostside/realtime.h
hostside/resolve.c
hostside/safety.h
layout/layout-data.h

index 21eef04e61241576530ba166dffc280b4df9a463..c371b1371edacdda9ced5dc389ae0cfbb471fac5 100644 (file)
@@ -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; i<polarityinsn.l-1; i++)
+    polarityinsn.d[i] |= 0x80;
 }
 
 void actual_inversions_segment(Segment *seg) {
index 51cec7925b5362d936082b472bf60279e1b007b6..376b20855e055114cc7a2b54283317db5bb27506 100644 (file)
@@ -46,7 +46,7 @@ static void *cmdi_ifok(oop_source *evts, oop_read *cl_read,
 
 void cmdin_new(CommandInput *cmdi, int readfd) {
   int r;
-  
+
   obc_init(&cmdi->out);
 
   events->on_fd(events, readfd, OOP_EXCEPTION, cmdi_exception, cmdi);
index 0db79631e8462cbd2e8cb9a39cb7b561f02790f9..2fd57d418121d518db108a734211e2520e7b5047 100644 (file)
@@ -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;
 };
 
index 040ee6a5c50c0765c792648c32505fc6ff3bf585..33ab3f26b453ade0203c75020028309e2fd3d865 100644 (file)
@@ -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);
index e7faccf833c601fccbe9f47cefed676c57c609a7..13eff3727ae2dfe8fed061d412f59086b46896c7 100644 (file)
@@ -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 ----------*/
index 99544ce34a66b37aceeeb89a2895292984703934..ae2082b610c60fdef975a9610930a921c4e71782 100644 (file)
@@ -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) {
index ca5e10128677900bc7820d52c1e61b5fd188ab13..c5c152635c1efa7b07eda1242de4cbcc3ac679f0 100644 (file)
@@ -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);
 
index 2dfc6a62decfc987a875e10dd9ad8cdb1a76eb8e..317f9ac51104b1ad3ec38b29a56e7088b649b872 100644 (file)
@@ -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;
index 95d4e27a494482b5bd0b45766fc4a609d23a639e..8e6d0e5c6b31f5766aaedd2c6b98d804427e236a 100644 (file)
@@ -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)           \
index 4bb569a564bcdb8a9742dac8439680f52631f6c7..d5900b3c0bc41c6d2da378ec3825d6b10b17bd81 100644 (file)
@@ -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*/