Subject: Re: Problems with SoundBlaster Live!
To: None <toshii@netbsd.org>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: current-users
Date: 03/18/2003 01:13:49
In article <20030317160352.9A47F6C3E@mail.asahi-net.or.jp>
toshii@netbsd.org wrote:
> This complexity only saves one or two free&malloc per device open,
> and I wasn't sure which way is better.
> This is the behavior of the old code (before I add recording
> support), but I don't have particular opinion.
Then, how about this?
---
Index: emuxki.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/emuxki.c,v
retrieving revision 1.24
diff -u -r1.24 emuxki.c
--- emuxki.c 2003/03/17 12:29:09 1.24
+++ emuxki.c 2003/03/17 15:12:00
@@ -1297,32 +1297,32 @@
sc->lvoice = NULL;
splx(s);
- if (!voice) {
- if (!(voice = malloc(sizeof(*voice), M_DEVBUF, M_WAITOK)))
- return (NULL);
- } else if (voice->use != use)
- emuxki_voice_dataloc_destroy(voice);
- else
- goto skip_initialize;
+ if (voice == NULL || voice->use != use) {
+ if (voice == NULL) {
+ if ((voice = malloc(sizeof(*voice), M_DEVBUF,
+ M_WAITOK)) == NULL)
+ return (NULL);
+ } else
+ emuxki_voice_dataloc_destroy(voice);
- voice->sc = sc;
- voice->state = !EMU_VOICE_STATE_STARTED;
- voice->stereo = EMU_VOICE_STEREO_NOTSET;
- voice->b16 = 0;
- voice->sample_rate = 0;
- if (use & EMU_VOICE_USE_PLAY)
- voice->dataloc.chan[0] = voice->dataloc.chan[1] = NULL;
- else
- voice->dataloc.source = EMU_RECSRC_NOTSET;
- voice->buffer = NULL;
- voice->blksize = 0;
- voice->trigblk = 0;
- voice->blkmod = 0;
- voice->inth = NULL;
- voice->inthparam = NULL;
- voice->use = use;
+ voice->sc = sc;
+ voice->state = !EMU_VOICE_STATE_STARTED;
+ voice->stereo = EMU_VOICE_STEREO_NOTSET;
+ voice->b16 = 0;
+ voice->sample_rate = 0;
+ if (use & EMU_VOICE_USE_PLAY)
+ voice->dataloc.chan[0] = voice->dataloc.chan[1] = NULL;
+ else
+ voice->dataloc.source = EMU_RECSRC_NOTSET;
+ voice->buffer = NULL;
+ voice->blksize = 0;
+ voice->trigblk = 0;
+ voice->blkmod = 0;
+ voice->inth = NULL;
+ voice->inthparam = NULL;
+ voice->use = use;
+ }
-skip_initialize:
s = splaudio();
LIST_INSERT_HEAD((&sc->voices), voice, next);
splx(s);
---