Commit fab068cd authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Restructure flush_source and flush_old_sources.

Now flush_source itself checks for the source being flushable.
parent d6b8ddd8
...@@ -88,14 +88,26 @@ find_source(const unsigned char *id, const unsigned char *p, unsigned char plen, ...@@ -88,14 +88,26 @@ find_source(const unsigned char *id, const unsigned char *p, unsigned char plen,
return src; return src;
} }
/* It is the caller's responsibility to check that no routes point at int
this source. */
void
flush_source(struct source *src) flush_source(struct source *src)
{ {
int i;
for(i = 0; i < numroutes; i++) {
if(routes[i].src == src)
return 0;
}
memset(src, 0, sizeof(*src)); memset(src, 0, sizeof(*src));
VALGRIND_MAKE_MEM_UNDEFINED(src, sizeof(*src)); VALGRIND_MAKE_MEM_UNDEFINED(src, sizeof(*src));
src->valid = 0; src->valid = 0;
while(numsrcs > 0 && !srcs[numsrcs - 1].valid) {
numsrcs--;
VALGRIND_MAKE_MEM_UNDEFINED(&srcs[numsrcs], sizeof(srcs[numsrcs]));
}
return 1;
} }
struct source * struct source *
...@@ -147,7 +159,7 @@ update_source(struct source *src, ...@@ -147,7 +159,7 @@ update_source(struct source *src,
int int
flush_old_sources() flush_old_sources()
{ {
int i, j, changed; int i, changed, rc;
changed = 0; changed = 0;
...@@ -156,21 +168,8 @@ flush_old_sources() ...@@ -156,21 +168,8 @@ flush_old_sources()
continue; continue;
if(srcs[i].time >= now.tv_sec - SOURCE_GC_TIME) if(srcs[i].time >= now.tv_sec - SOURCE_GC_TIME)
continue; continue;
for(j = 0; j < numroutes; j++) { rc = flush_source(&srcs[i]);
if(routes[j].src == &srcs[i]) changed = changed || rc;
goto nocando;
}
flush_source(&srcs[i]);
changed = 1;
nocando:
;
}
if(changed) {
while(numsrcs > 0 && !srcs[numsrcs - 1].valid) {
numsrcs--;
VALGRIND_MAKE_MEM_UNDEFINED(&srcs[numsrcs], sizeof(srcs[numsrcs]));
}
} }
return changed; return changed;
......
...@@ -38,7 +38,7 @@ struct source *find_source(const unsigned char *id, ...@@ -38,7 +38,7 @@ struct source *find_source(const unsigned char *id,
const unsigned char *p, const unsigned char *p,
unsigned char plen, unsigned char plen,
int create, unsigned short seqno); int create, unsigned short seqno);
void flush_source(struct source *src); int flush_source(struct source *src);
struct source *find_recent_source(const unsigned char *p, struct source *find_recent_source(const unsigned char *p,
unsigned char plen); unsigned char plen);
void update_source(struct source *src, void update_source(struct source *src,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment