summaryrefslogtreecommitdiff
path: root/usr.bin/aucat
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2009-08-26 08:28:22 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2009-08-26 08:28:22 +0000
commit876c092c9bb8f29908740d38aad602425ba78e11 (patch)
treef2be3320bc9bfea1d2cec97b6b8cd2ee0d2296e9 /usr.bin/aucat
parentb9fc547357083462411a831a3b9a8422c172b9f6 (diff)
when allocating the midi channel for the volume control of a new
client, pick the oldest unused channel rather than the first found. This way new clients don't reuse channels of recently used applications, thus improving a lot the client<->channel affinity.
Diffstat (limited to 'usr.bin/aucat')
-rw-r--r--usr.bin/aucat/aproc.h4
-rw-r--r--usr.bin/aucat/midi.c32
2 files changed, 25 insertions, 11 deletions
diff --git a/usr.bin/aucat/aproc.h b/usr.bin/aucat/aproc.h
index 6911d849473..f63ed1aff35 100644
--- a/usr.bin/aucat/aproc.h
+++ b/usr.bin/aucat/aproc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: aproc.h,v 1.20 2009/08/26 06:10:15 ratchov Exp $ */
+/* $OpenBSD: aproc.h,v 1.21 2009/08/26 08:28:21 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -169,11 +169,13 @@ struct aproc {
struct {
#define CTL_NSLOT 8
#define CTL_NAMEMAX 8
+ unsigned serial;
struct ctl_slot {
void (*cb)(void *, unsigned);
void *arg;
unsigned unit;
char name[CTL_NAMEMAX];
+ unsigned serial;
} slot[CTL_NSLOT];
} ctl;
} u;
diff --git a/usr.bin/aucat/midi.c b/usr.bin/aucat/midi.c
index f93f05d2a43..541d314de52 100644
--- a/usr.bin/aucat/midi.c
+++ b/usr.bin/aucat/midi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: midi.c,v 1.5 2009/08/26 06:10:15 ratchov Exp $ */
+/* $OpenBSD: midi.c,v 1.6 2009/08/26 08:28:21 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -331,6 +331,7 @@ ctl_slotnew(struct aproc *p, char *who, void (*cb)(void *, unsigned), void *arg)
struct ctl_slot *slot;
char name[CTL_NAMEMAX];
unsigned i, unit, umap = 0;
+ unsigned ser, bestser, bestidx;
/*
* create a ``valid'' control name (lowcase, remove [^a-z], trucate)
@@ -380,20 +381,29 @@ ctl_slotnew(struct aproc *p, char *who, void (*cb)(void *, unsigned), void *arg)
}
/*
- * couldn't find a matching slot, pick the first free one
+ * couldn't find a matching slot, pick oldest free slot
*/
- for (i = 0, slot = p->u.ctl.slot; ; i++, slot++) {
- if (i == CTL_NSLOT)
- return -1;
- if (slot->cb == NULL)
- break;
+ bestser = 0;
+ bestidx = CTL_NSLOT;
+ for (i = 0, slot = p->u.ctl.slot; i < CTL_NSLOT; i++, slot++) {
+ if (slot->cb != NULL)
+ continue;
+ ser = p->u.ctl.serial - slot->serial;
+ if (ser > bestser) {
+ bestser = ser;
+ bestidx = i;
+ }
}
- DPRINTFN(1, "ctl_newslot: overwritten %u\n", i);
+ if (bestidx == CTL_NSLOT)
+ return -1;
+ slot = p->u.ctl.slot + bestidx;
strlcpy(slot->name, name, CTL_NAMEMAX);
+ slot->serial = p->u.ctl.serial++;
slot->unit = unit;
slot->cb = cb;
slot->arg = arg;
- return i;
+ DPRINTFN(1, "ctl_newslot: %u overwritten)\n", bestidx);
+ return bestidx;
}
void
@@ -509,7 +519,7 @@ ctl_done(struct aproc *p)
for (i = 0, s = p->u.ctl.slot; i < CTL_NSLOT; i++, s++) {
if (s->cb != NULL)
- DPRINTF("ctl_done: %s%u not freed\n", s->name, s->unit);
+ DPRINTF("ctl_done: %s%u in use\n", s->name, s->unit);
}
}
@@ -534,9 +544,11 @@ ctl_new(char *name)
unsigned i;
p = aproc_new(&ctl_ops, name);
+ p->u.ctl.serial = 0;
for (i = 0, s = p->u.ctl.slot; i < CTL_NSLOT; i++, s++) {
p->u.ctl.slot[i].unit = i;
p->u.ctl.slot[i].cb = NULL;
+ p->u.ctl.slot[i].serial = p->u.ctl.serial++;
strlcpy(p->u.ctl.slot[i].name, "unknown", CTL_NAMEMAX);
}
return p;