From 1853f5d6594bc371e4d8e631c24acd011a620915 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 9 Aug 2025 17:20:05 +0300 Subject: refactor mesh3d to match 2d,1d --- src/common.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/common.c (limited to 'src/common.c') diff --git a/src/common.c b/src/common.c new file mode 100644 index 0000000..41bd145 --- /dev/null +++ b/src/common.c @@ -0,0 +1,45 @@ +#include + +stat place_reg(struct reg *r, struct packet pkt) +{ + if (r->busy) + return EBUSY; + + r->pkt = pkt; + r->busy = true; + return OK; +} + +stat copy_reg(struct reg *r, struct reg *s) +{ + assert(s->busy); + if (r->busy) + return EBUSY; + + r->pkt = s->pkt; + r->busy = true; + s->busy = false; + return OK; +} + +void propagate(struct reg *out, + size_t count, struct reg *in[static count], + bool (*sel)(struct reg *r, void *data), void *data) +{ + struct reg *r = NULL; + for (size_t i = 0; i < count; ++i) { + if (!in[i] || !in[i]->busy) + continue; + + if (!sel(in[i], data)) + continue; + + if (!r || r->pkt.timestamp > in[i]->pkt.timestamp) + r = in[i]; + } + + if (!r) + return; + + copy_reg(out, r); +} -- cgit v1.3