mirror of https://github.com/ericonr/sndio.git
Replace the "umap" bitmap by a simple table of slot pointers.
Makes the code simpler at virtually no cost since we need 8 entries only. No behavior change.
This commit is contained in:
parent
e6579625a0
commit
d2985fff2b
41
sndiod/dev.c
41
sndiod/dev.c
|
@ -1534,8 +1534,8 @@ slot_new(struct dev *d, struct opt *opt, char *who,
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
char name[SLOT_NAMEMAX];
|
char name[SLOT_NAMEMAX];
|
||||||
unsigned int i, unit, umap = 0;
|
unsigned int i, ser, bestser, bestidx;
|
||||||
unsigned int ser, bestser, bestidx;
|
struct slot *unit[DEV_NSLOT];
|
||||||
struct slot *s;
|
struct slot *s;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1554,30 +1554,26 @@ slot_new(struct dev *d, struct opt *opt, char *who,
|
||||||
strlcpy(name, "noname", SLOT_NAMEMAX);
|
strlcpy(name, "noname", SLOT_NAMEMAX);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* find the first unused "unit" number for this name
|
* build a unit-to-slot map for this name
|
||||||
*/
|
*/
|
||||||
for (i = 0, s = d->slot; i < DEV_NSLOT; i++, s++) {
|
for (i = 0; i < DEV_NSLOT; i++)
|
||||||
if (s->ops == NULL)
|
unit[i] = NULL;
|
||||||
continue;
|
for (i = 0; i < DEV_NSLOT; i++) {
|
||||||
|
s = d->slot + i;
|
||||||
if (strcmp(s->name, name) == 0)
|
if (strcmp(s->name, name) == 0)
|
||||||
umap |= (1 << s->unit);
|
unit[s->unit] = s;
|
||||||
}
|
|
||||||
for (unit = 0; ; unit++) {
|
|
||||||
if ((umap & (1 << unit)) == 0)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* find a free controller slot with the same name/unit
|
* find the free slot with the least unit number
|
||||||
*/
|
*/
|
||||||
for (i = 0, s = d->slot; i < DEV_NSLOT; i++, s++) {
|
for (i = 0; i < DEV_NSLOT; i++) {
|
||||||
if (s->ops == NULL &&
|
s = unit[i];
|
||||||
strcmp(s->name, name) == 0 &&
|
if (s != NULL && s->ops == NULL) {
|
||||||
s->unit == unit) {
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (log_level >= 3) {
|
if (log_level >= 3) {
|
||||||
log_puts(name);
|
log_puts(s->name);
|
||||||
log_putu(unit);
|
log_putu(s->unit);
|
||||||
log_puts(": reused\n");
|
log_puts(": reused\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1605,11 +1601,13 @@ slot_new(struct dev *d, struct opt *opt, char *who,
|
||||||
s->vol = MIDI_MAXCTL;
|
s->vol = MIDI_MAXCTL;
|
||||||
strlcpy(s->name, name, SLOT_NAMEMAX);
|
strlcpy(s->name, name, SLOT_NAMEMAX);
|
||||||
s->serial = d->serial++;
|
s->serial = d->serial++;
|
||||||
s->unit = unit;
|
for (i = 0; unit[i] != NULL; i++)
|
||||||
|
; /* nothing */
|
||||||
|
s->unit = i;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (log_level >= 3) {
|
if (log_level >= 3) {
|
||||||
log_puts(name);
|
log_puts(s->name);
|
||||||
log_putu(unit);
|
log_putu(s->unit);
|
||||||
log_puts(": overwritten slot ");
|
log_puts(": overwritten slot ");
|
||||||
log_putu(bestidx);
|
log_putu(bestidx);
|
||||||
log_puts("\n");
|
log_puts("\n");
|
||||||
|
@ -1619,7 +1617,6 @@ slot_new(struct dev *d, struct opt *opt, char *who,
|
||||||
}
|
}
|
||||||
if (log_level >= 1) {
|
if (log_level >= 1) {
|
||||||
log_puts(name);
|
log_puts(name);
|
||||||
log_putu(unit);
|
|
||||||
log_puts(": out of sub-device slots\n");
|
log_puts(": out of sub-device slots\n");
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue