From 4710960bbe9728a43f6a3bd913a87c4c7896348c Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Wed, 2 Dec 2020 21:54:33 +0100 Subject: [PATCH] Move the control client state out of the device structure --- sndiod/dev.c | 20 ++++++++------------ sndiod/dev.h | 8 ++++++-- sndiod/sock.c | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sndiod/dev.c b/sndiod/dev.c index 09ab186..fba20ec 100644 --- a/sndiod/dev.c +++ b/sndiod/dev.c @@ -110,6 +110,7 @@ struct slotops zomb_slotops = { struct dev *dev_list = NULL; unsigned int dev_sndnum = 0; +struct ctlslot ctlslot_array[DEV_NCTLSLOT]; struct slot slot_array[DEV_NSLOT]; unsigned int slot_serial; /* for slot allocation */ @@ -1034,7 +1035,6 @@ dev_new(char *path, struct aparams *par, unsigned int rate, unsigned int hold, unsigned int autovol) { struct dev *d; - unsigned int i; if (dev_sndnum == DEV_NMAX) { if (log_level >= 1) @@ -1067,12 +1067,6 @@ dev_new(char *path, struct aparams *par, d->autovol = autovol; d->refcnt = 0; d->pstate = DEV_CFG; - for (i = 0; i < DEV_NCTLSLOT; i++) { - d->ctlslot[i].ops = NULL; - d->ctlslot[i].dev = d; - d->ctlslot[i].mask = 0; - d->ctlslot[i].mode = 0; - } d->slot_list = NULL; d->master = MIDI_MAXCTL; d->mtc.origin = 0; @@ -1286,7 +1280,9 @@ dev_abort(struct dev *d) } d->slot_list = NULL; - for (c = d->ctlslot, i = DEV_NCTLSLOT; i > 0; i--, c++) { + for (c = ctlslot_array, i = DEV_NCTLSLOT; i > 0; i--, c++) { + if (c->dev != d) + continue; if (c->ops) c->ops->exit(c->arg); c->ops = NULL; @@ -2321,7 +2317,7 @@ ctlslot_new(struct dev *d, struct ctlops *ops, void *arg) for (;;) { if (i == DEV_NCTLSLOT) return NULL; - s = d->ctlslot + i; + s = ctlslot_array + i; if (s->ops == NULL) break; i++; @@ -2426,7 +2422,7 @@ dev_addctl(struct dev *d, char *gstr, int type, int addr, c->refs_mask = 0; for (i = 0; i < DEV_NCTLSLOT; i++) { c->refs_mask |= CTL_DEVMASK; - if (d->ctlslot[i].ops != NULL) + if (ctlslot_array[i].ops != NULL) c->refs_mask |= 1 << i; } for (pc = &d->ctl_list; *pc != NULL; pc = &(*pc)->next) @@ -2512,8 +2508,8 @@ dev_ctlsync(struct dev *d) "output", -1, "level", NULL, -1, 127, d->master); } - for (s = d->ctlslot, i = DEV_NCTLSLOT; i > 0; i--, s++) { - if (s->ops) + for (s = ctlslot_array, i = DEV_NCTLSLOT; i > 0; i--, s++) { + if (s->dev == d && s->ops) s->ops->sync(s->arg); } } diff --git a/sndiod/dev.h b/sndiod/dev.h index 45fe5aa..8763823 100644 --- a/sndiod/dev.h +++ b/sndiod/dev.h @@ -32,6 +32,11 @@ */ #define DEV_NSLOT 8 +/* + * preallocated control clients + */ +#define DEV_NCTLSLOT 8 + /* * audio stream state structure */ @@ -258,12 +263,11 @@ struct dev { */ struct ctl *ctl_list; -#define DEV_NCTLSLOT 8 - struct ctlslot ctlslot[DEV_NCTLSLOT]; }; extern struct dev *dev_list; extern struct slot slot_array[DEV_NSLOT]; +extern struct ctlslot ctlslot_array[DEV_NCTLSLOT]; void slot_array_init(void); diff --git a/sndiod/sock.c b/sndiod/sock.c index 525970c..d7ec79d 100644 --- a/sndiod/sock.c +++ b/sndiod/sock.c @@ -114,7 +114,7 @@ sock_log(struct sock *f) midi_log(f->midi); else if (f->ctlslot) { log_puts("ctlslot"); - log_putu(f->ctlslot - f->ctlslot->dev->ctlslot); + log_putu(f->ctlslot - ctlslot_array); } else log_puts("sock"); #ifdef DEBUG