Received: from eggs.gnu.org ([2001:4830:134:3::10]:41348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUBSG-0000ms-83 for qemu-devel@nongnu.org; Mon, 01 Aug 2016 07:32:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bUBSB-0003Kn-8B for qemu-devel@nongnu.org; Mon, 01 Aug 2016 07:32:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42226) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUBSA-0003Kg-VZ for qemu-devel@nongnu.org; Mon, 01 Aug 2016 07:32:15 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9418F85547 for ; Mon, 1 Aug 2016 11:32:14 +0000 (UTC) References: <20160801112343.29082-1-marcandre.lureau@redhat.com> <20160801112343.29082-3-marcandre.lureau@redhat.com> From: Paolo Bonzini Message-ID: <3f8460f7-d364-78e1-dc52-0a3cf8141f18@redhat.com> Date: Mon, 1 Aug 2016 13:32:07 +0200 MIME-Version: 1.0 In-Reply-To: <20160801112343.29082-3-marcandre.lureau@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH for-2.7 2/2] audio: clean up before monitor clean up List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org, Gerd Hoffmann , Markus Armbruster On 01/08/2016 13:23, marcandre.lureau@redhat.com wrote: > From: Marc-Andr=C3=A9 Lureau >=20 > Since aa5cb7f5e, the chardevs are being cleaned up when leaving qemu, > before the atexit() handlers. audio_cleanup() may use the monitor to > notify of changes. For compatibility reasons, let's clean up audio > before the monitor so it keeps emitting monitor events. >=20 > The audio_atexit() function is made idempotent (so it can be called > multiple times), That's a very good idea, as it avoids having to establish exit notifiers as we did for net/. Reviewed-by: Paolo Bonzini The two patches conflict with each other, so it's probably easiest if one of Gerd or Markus takes both. Thanks, Paolo > and renamed to audio_cleanup(). Since coreaudio > backend is using a 'isAtexit' code path, change it to check > audio_is_cleaning_up() instead, so the path is taken during normal > exit. >=20 > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > audio/audio.c | 26 ++++++++++++++++++-------- > audio/audio.h | 3 +++ > audio/coreaudio.c | 12 ++---------- > vl.c | 1 + > 4 files changed, 24 insertions(+), 18 deletions(-) >=20 > diff --git a/audio/audio.c b/audio/audio.c > index 9d4dcc7..c845a44 100644 > --- a/audio/audio.c > +++ b/audio/audio.c > @@ -1739,13 +1739,21 @@ static void audio_vm_change_state_handler (void= *opaque, int running, > audio_reset_timer (s); > } > =20 > -static void audio_atexit (void) > +static bool is_cleaning_up; > + > +bool audio_is_cleaning_up(void) > +{ > + return is_cleaning_up; > +} > + > +void audio_cleanup(void) > { > AudioState *s =3D &glob_audio_state; > - HWVoiceOut *hwo =3D NULL; > - HWVoiceIn *hwi =3D NULL; > + HWVoiceOut *hwo, *hwon; > + HWVoiceIn *hwi, *hwin; > =20 > - while ((hwo =3D audio_pcm_hw_find_any_out (hwo))) { > + is_cleaning_up =3D true; > + QLIST_FOREACH_SAFE(hwo, &glob_audio_state.hw_head_out, entries, hw= on) { > SWVoiceCap *sc; > =20 > if (hwo->enabled) { > @@ -1761,17 +1769,20 @@ static void audio_atexit (void) > cb->ops.destroy (cb->opaque); > } > } > + QLIST_REMOVE(hwo, entries); > } > =20 > - while ((hwi =3D audio_pcm_hw_find_any_in (hwi))) { > + QLIST_FOREACH_SAFE(hwi, &glob_audio_state.hw_head_in, entries, hwi= n) { > if (hwi->enabled) { > hwi->pcm_ops->ctl_in (hwi, VOICE_DISABLE); > } > hwi->pcm_ops->fini_in (hwi); > + QLIST_REMOVE(hwi, entries); > } > =20 > if (s->drv) { > s->drv->fini (s->drv_opaque); > + s->drv =3D NULL; > } > } > =20 > @@ -1799,7 +1810,7 @@ static void audio_init (void) > QLIST_INIT (&s->hw_head_out); > QLIST_INIT (&s->hw_head_in); > QLIST_INIT (&s->cap_head); > - atexit (audio_atexit); > + atexit(audio_cleanup); > =20 > s->ts =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s); > =20 > @@ -1966,8 +1977,7 @@ CaptureVoiceOut *AUD_add_capture ( > QLIST_INSERT_HEAD (&s->cap_head, cap, entries); > QLIST_INSERT_HEAD (&cap->cb_head, cb, entries); > =20 > - hw =3D NULL; > - while ((hw =3D audio_pcm_hw_find_any_out (hw))) { > + QLIST_FOREACH(hw, &glob_audio_state.hw_head_out, entries) { > audio_attach_capture (hw); > } > return cap; > diff --git a/audio/audio.h b/audio/audio.h > index 11e56c9..c3c5198 100644 > --- a/audio/audio.h > +++ b/audio/audio.h > @@ -163,4 +163,7 @@ static inline void *advance (void *p, int incr) > int wav_start_capture (CaptureState *s, const char *path, int freq, > int bits, int nchannels); > =20 > +bool audio_is_cleaning_up(void); > +void audio_cleanup(void); > + > #endif /* QEMU_AUDIO_H */ > diff --git a/audio/coreaudio.c b/audio/coreaudio.c > index d4ad224..c751420 100644 > --- a/audio/coreaudio.c > +++ b/audio/coreaudio.c > @@ -36,8 +36,6 @@ > #define MAC_OS_X_VERSION_10_6 1060 > #endif > =20 > -static int isAtexit; > - > typedef struct { > int buffer_frames; > int nbuffers; > @@ -378,11 +376,6 @@ static inline UInt32 isPlaying (AudioDeviceID outp= utDeviceID) > return result; > } > =20 > -static void coreaudio_atexit (void) > -{ > - isAtexit =3D 1; > -} > - > static int coreaudio_lock (coreaudioVoiceOut *core, const char *fn_nam= e) > { > int err; > @@ -630,7 +623,7 @@ static void coreaudio_fini_out (HWVoiceOut *hw) > int err; > coreaudioVoiceOut *core =3D (coreaudioVoiceOut *) hw; > =20 > - if (!isAtexit) { > + if (!audio_is_cleaning_up()) { > /* stop playback */ > if (isPlaying(core->outputDeviceID)) { > status =3D AudioDeviceStop(core->outputDeviceID, core->iop= rocid); > @@ -673,7 +666,7 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int c= md, ...) > =20 > case VOICE_DISABLE: > /* stop playback */ > - if (!isAtexit) { > + if (!audio_is_cleaning_up()) { > if (isPlaying(core->outputDeviceID)) { > status =3D AudioDeviceStop(core->outputDeviceID, > core->ioprocid); > @@ -697,7 +690,6 @@ static void *coreaudio_audio_init (void) > CoreaudioConf *conf =3D g_malloc(sizeof(CoreaudioConf)); > *conf =3D glob_conf; > =20 > - atexit(coreaudio_atexit); > return conf; > } > =20 > diff --git a/vl.c b/vl.c > index a14c438..c4eeaff 100644 > --- a/vl.c > +++ b/vl.c > @@ -4612,6 +4612,7 @@ int main(int argc, char **argv, char **envp) > =20 > /* vhost-user must be cleaned up before chardevs. */ > net_cleanup(); > + audio_cleanup(); > monitor_cleanup(); > qemu_chr_cleanup(); > =20 >=20