From: ratchov Date: Fri, 29 Jan 2021 11:21:00 +0000 (+0000) Subject: Move the options list out of the device structure X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5684d55073817e9c232f4b049db99054a428e9a8;p=openbsd Move the options list out of the device structure No behavior change. Later this will ease applying the configuration of one device to another by "just" swapping pointers. --- diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c index 83e577f7fa1..07b85f7eb55 100644 --- a/usr.bin/sndiod/dev.c +++ b/usr.bin/sndiod/dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.85 2021/01/29 10:55:19 ratchov Exp $ */ +/* $OpenBSD: dev.c,v 1.86 2021/01/29 11:21:00 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -1044,7 +1044,6 @@ dev_new(char *path, struct aparams *par, d->alt_list = NULL; dev_addname(d,path); d->num = dev_sndnum++; - d->opt_list = NULL; d->alt_num = -1; /* @@ -1501,8 +1500,6 @@ dev_del(struct dev *d) log_puts(": deleting\n"); } #endif - while (d->opt_list != NULL) - opt_del(d, d->opt_list); if (d->pstate != DEV_CFG) dev_close(d); for (p = &dev_list; *p != d; p = &(*p)->next) { diff --git a/usr.bin/sndiod/dev.h b/usr.bin/sndiod/dev.h index 81150bd9a4b..35c4f34113c 100644 --- a/usr.bin/sndiod/dev.h +++ b/usr.bin/sndiod/dev.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.h,v 1.33 2021/01/29 10:55:19 ratchov Exp $ */ +/* $OpenBSD: dev.h,v 1.34 2021/01/29 11:21:00 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -114,18 +114,6 @@ struct slot { unsigned int id; /* process id */ }; -struct opt { - struct opt *next; -#define OPT_NAMEMAX 11 - char name[OPT_NAMEMAX + 1]; - int maxweight; /* max dynamic range for clients */ - int pmin, pmax; /* play channels */ - int rmin, rmax; /* recording channels */ - int mmc; /* true if MMC control enabled */ - int dup; /* true if join/expand enabled */ - int mode; /* bitmap of MODE_XXX */ -}; - /* * subset of channels of a stream */ @@ -171,7 +159,6 @@ struct ctlslot { struct dev { struct dev *next; struct slot *slot_list; /* audio streams attached */ - struct opt *opt_list; struct midi *midi; /* diff --git a/usr.bin/sndiod/opt.c b/usr.bin/sndiod/opt.c index 9f5477c38ac..aff4bb2f573 100644 --- a/usr.bin/sndiod/opt.c +++ b/usr.bin/sndiod/opt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: opt.c,v 1.4 2018/06/26 07:12:35 ratchov Exp $ */ +/* $OpenBSD: opt.c,v 1.5 2021/01/29 11:21:00 ratchov Exp $ */ /* * Copyright (c) 2008-2011 Alexandre Ratchov * @@ -20,6 +20,8 @@ #include "opt.h" #include "utils.h" +struct opt *opt_list; + /* * create a new audio sub-device "configuration" */ @@ -54,6 +56,7 @@ opt_new(struct dev *d, char *name, } } o = xmalloc(sizeof(struct opt)); + o->dev = d; if (mode & MODE_PLAY) { o->pmin = pmin; o->pmax = pmax; @@ -67,8 +70,8 @@ opt_new(struct dev *d, char *name, o->dup = dup; o->mode = mode; memcpy(o->name, name, len + 1); - o->next = d->opt_list; - d->opt_list = o; + o->next = opt_list; + opt_list = o; if (log_level >= 2) { dev_log(d); log_puts("."); @@ -110,7 +113,9 @@ opt_byname(struct dev *d, char *name) { struct opt *o; - for (o = d->opt_list; o != NULL; o = o->next) { + for (o = opt_list; o != NULL; o = o->next) { + if (d != NULL && o->dev != d) + continue; if (strcmp(name, o->name) == 0) return o; } @@ -118,11 +123,11 @@ opt_byname(struct dev *d, char *name) } void -opt_del(struct dev *d, struct opt *o) +opt_del(struct opt *o) { struct opt **po; - for (po = &d->opt_list; *po != o; po = &(*po)->next) { + for (po = &opt_list; *po != o; po = &(*po)->next) { #ifdef DEBUG if (*po == NULL) { log_puts("opt_del: not on list\n"); diff --git a/usr.bin/sndiod/opt.h b/usr.bin/sndiod/opt.h index 31dcce25e61..9c12639aec5 100644 --- a/usr.bin/sndiod/opt.h +++ b/usr.bin/sndiod/opt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: opt.h,v 1.2 2018/06/26 07:12:35 ratchov Exp $ */ +/* $OpenBSD: opt.h,v 1.3 2021/01/29 11:21:00 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -19,9 +19,24 @@ struct dev; +struct opt { + struct opt *next; + struct dev *dev; +#define OPT_NAMEMAX 11 + char name[OPT_NAMEMAX + 1]; + int maxweight; /* max dynamic range for clients */ + int pmin, pmax; /* play channels */ + int rmin, rmax; /* recording channels */ + int mmc; /* true if MMC control enabled */ + int dup; /* true if join/expand enabled */ + int mode; /* bitmap of MODE_XXX */ +}; + +extern struct opt *opt_list; + struct opt *opt_new(struct dev *, char *, int, int, int, int, int, int, int, unsigned int); -void opt_del(struct dev *, struct opt *); +void opt_del(struct opt *); struct opt *opt_byname(struct dev *, char *); #endif /* !defined(OPT_H) */ diff --git a/usr.bin/sndiod/sndiod.c b/usr.bin/sndiod/sndiod.c index 4042594f36a..23e5966d26e 100644 --- a/usr.bin/sndiod/sndiod.c +++ b/usr.bin/sndiod/sndiod.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sndiod.c,v 1.42 2021/01/29 10:51:24 ratchov Exp $ */ +/* $OpenBSD: sndiod.c,v 1.43 2021/01/29 11:21:00 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -700,6 +700,8 @@ main(int argc, char **argv) ; /* nothing */ midi_done(); + while (opt_list) + opt_del(opt_list); while (dev_list) dev_del(dev_list); while (port_list)