summaryrefslogtreecommitdiff
path: root/usr.bin/aucat/aproc.c
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2008-12-29 17:59:09 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2008-12-29 17:59:09 +0000
commit6c4053031259f10fa0060a0e39acee631e2ec026 (patch)
tree66ba65b8cf26b209e036989b3a86d0acfa0675be /usr.bin/aucat/aproc.c
parent82b6a7781a258d770c4104783c04017b0acc5eeb (diff)
make the code "more correct": add reference counters to aproc
structures so we can keep a pointer to the device. Beside some simplifications, this allows to easily handle the situation where the audio device desappears. No change in the behaviour.
Diffstat (limited to 'usr.bin/aucat/aproc.c')
-rw-r--r--usr.bin/aucat/aproc.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/usr.bin/aucat/aproc.c b/usr.bin/aucat/aproc.c
index 101489b520a..f7f417b8c19 100644
--- a/usr.bin/aucat/aproc.c
+++ b/usr.bin/aucat/aproc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aproc.c,v 1.29 2008/12/27 17:02:13 ratchov Exp $ */
+/* $OpenBSD: aproc.c,v 1.30 2008/12/29 17:59:08 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -67,6 +67,7 @@ aproc_new(struct aproc_ops *ops, char *name)
LIST_INIT(&p->obuflist);
p->name = name;
p->ops = ops;
+ p->refs = 0;
return p;
}
@@ -88,6 +89,10 @@ aproc_del(struct aproc *p)
i = LIST_FIRST(&p->obuflist);
abuf_eof(i);
}
+ if (p->refs > 0) {
+ DPRINTF("aproc_del: %s(%s): has refs\n", p->ops->name, p->name);
+ return;
+ }
DPRINTF("aproc_del: %s(%s): freed\n", p->ops->name, p->name);
free(p);
}
@@ -199,9 +204,12 @@ rpipe_done(struct aproc *p)
{
struct file *f = p->u.io.file;
+ if (f == NULL)
+ return;
f->rproc = NULL;
if (f->wproc == NULL)
file_del(f);
+ p->u.io.file = NULL;
}
void
@@ -247,9 +255,12 @@ wpipe_done(struct aproc *p)
{
struct file *f = p->u.io.file;
+ if (f == NULL)
+ return;
f->wproc = NULL;
if (f->rproc == NULL)
file_del(f);
+ p->u.io.file = NULL;
}
int