From nobody Mon May 6 23:52:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549336753772392.06142618812305; Mon, 4 Feb 2019 19:19:13 -0800 (PST) Received: from localhost ([127.0.0.1]:53233 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrGN-0000GB-JR for importer@patchew.org; Mon, 04 Feb 2019 22:19:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrEM-0007a6-PF for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:17:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqr6F-0002bL-Bm for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:08:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38246) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqr6B-0002ZH-TR; Mon, 04 Feb 2019 22:08:37 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03E0886673; Tue, 5 Feb 2019 03:08:35 +0000 (UTC) Received: from thuth.com (ovpn-116-65.phx2.redhat.com [10.3.116.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7C8F60F8A; Tue, 5 Feb 2019 03:08:33 +0000 (UTC) From: Thomas Huth To: Gerd Hoffmann , qemu-devel@nongnu.org Date: Tue, 5 Feb 2019 04:08:20 +0100 Message-Id: <1549336101-17623-2-git-send-email-thuth@redhat.com> In-Reply-To: <1549336101-17623-1-git-send-email-thuth@redhat.com> References: <1549336101-17623-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 05 Feb 2019 03:08:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] audio/sdlaudio: Remove the semaphore code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=20Zolt=C3=A1n?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The semaphore code was only working with SDL1.2 - with SDL2, it causes a deadlock. Since we've removed support for SDL1.2 recently, we can now completely remove the semaphore code from sdlaudio.c. Signed-off-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- audio/sdlaudio.c | 145 ++-------------------------------------------------= ---- 1 file changed, 5 insertions(+), 140 deletions(-) diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c index 9db5ac9..53bfdbf 100644 --- a/audio/sdlaudio.c +++ b/audio/sdlaudio.c @@ -38,14 +38,9 @@ #define AUDIO_CAP "sdl" #include "audio_int.h" =20 -#define USE_SEMAPHORE (SDL_MAJOR_VERSION < 2) - typedef struct SDLVoiceOut { HWVoiceOut hw; int live; -#if USE_SEMAPHORE - int rpos; -#endif int decr; } SDLVoiceOut; =20 @@ -57,10 +52,6 @@ static struct { =20 static struct SDLAudioState { int exit; -#if USE_SEMAPHORE - SDL_mutex *mutex; - SDL_sem *sem; -#endif int initialized; bool driver_created; } glob_sdl; @@ -77,66 +68,6 @@ static void GCC_FMT_ATTR (1, 2) sdl_logerr (const char *= fmt, ...) AUD_log (AUDIO_CAP, "Reason: %s\n", SDL_GetError ()); } =20 -static int sdl_lock (SDLAudioState *s, const char *forfn) -{ -#if USE_SEMAPHORE - if (SDL_LockMutex (s->mutex)) { - sdl_logerr ("SDL_LockMutex for %s failed\n", forfn); - return -1; - } -#else - SDL_LockAudio(); -#endif - - return 0; -} - -static int sdl_unlock (SDLAudioState *s, const char *forfn) -{ -#if USE_SEMAPHORE - if (SDL_UnlockMutex (s->mutex)) { - sdl_logerr ("SDL_UnlockMutex for %s failed\n", forfn); - return -1; - } -#else - SDL_UnlockAudio(); -#endif - - return 0; -} - -static int sdl_post (SDLAudioState *s, const char *forfn) -{ -#if USE_SEMAPHORE - if (SDL_SemPost (s->sem)) { - sdl_logerr ("SDL_SemPost for %s failed\n", forfn); - return -1; - } -#endif - - return 0; -} - -#if USE_SEMAPHORE -static int sdl_wait (SDLAudioState *s, const char *forfn) -{ - if (SDL_SemWait (s->sem)) { - sdl_logerr ("SDL_SemWait for %s failed\n", forfn); - return -1; - } - return 0; -} -#endif - -static int sdl_unlock_and_post (SDLAudioState *s, const char *forfn) -{ - if (sdl_unlock (s, forfn)) { - return -1; - } - - return sdl_post (s, forfn); -} - static int aud_to_sdlfmt (audfmt_e fmt) { switch (fmt) { @@ -243,9 +174,9 @@ static int sdl_open (SDL_AudioSpec *req, SDL_AudioSpec = *obt) static void sdl_close (SDLAudioState *s) { if (s->initialized) { - sdl_lock (s, "sdl_close"); + SDL_LockAudio(); s->exit =3D 1; - sdl_unlock_and_post (s, "sdl_close"); + SDL_UnlockAudio(); SDL_PauseAudio (1); SDL_CloseAudio (); s->initialized =3D 0; @@ -267,30 +198,10 @@ static void sdl_callback (void *opaque, Uint8 *buf, i= nt len) int to_mix, decr; =20 /* dolog ("in callback samples=3D%d\n", samples); */ -#if USE_SEMAPHORE - sdl_wait (s, "sdl_callback"); - if (s->exit) { - return; - } - - if (sdl_lock (s, "sdl_callback")) { - return; - } - - if (audio_bug(__func__, sdl->live < 0 || sdl->live > hw->samples))= { - dolog ("sdl->live=3D%d hw->samples=3D%d\n", - sdl->live, hw->samples); - return; - } =20 - if (!sdl->live) { - goto again; - } -#else if (s->exit || !sdl->live) { break; } -#endif =20 /* dolog ("in callback live=3D%d\n", live); */ to_mix =3D audio_MIN (samples, sdl->live); @@ -301,33 +212,20 @@ static void sdl_callback (void *opaque, Uint8 *buf, i= nt len) =20 /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk);= */ hw->clip (buf, src, chunk); -#if USE_SEMAPHORE - sdl->rpos =3D (sdl->rpos + chunk) % hw->samples; -#else hw->rpos =3D (hw->rpos + chunk) % hw->samples; -#endif to_mix -=3D chunk; buf +=3D chunk << hw->info.shift; } samples -=3D decr; sdl->live -=3D decr; sdl->decr +=3D decr; - -#if USE_SEMAPHORE - again: - if (sdl_unlock (s, "sdl_callback")) { - return; - } -#endif } /* dolog ("done len=3D%d\n", len); */ =20 -#if (SDL_MAJOR_VERSION >=3D 2) /* SDL2 does not clear the remaining buffer for us, so do it on our ow= n */ if (samples) { memset(buf, 0, samples << hw->info.shift); } -#endif } =20 static int sdl_write_out (SWVoiceOut *sw, void *buf, int len) @@ -339,11 +237,8 @@ static int sdl_run_out (HWVoiceOut *hw, int live) { int decr; SDLVoiceOut *sdl =3D (SDLVoiceOut *) hw; - SDLAudioState *s =3D &glob_sdl; =20 - if (sdl_lock (s, "sdl_run_out")) { - return 0; - } + SDL_LockAudio(); =20 if (sdl->decr > live) { ldebug ("sdl->decr %d live %d sdl->live %d\n", @@ -355,19 +250,10 @@ static int sdl_run_out (HWVoiceOut *hw, int live) decr =3D audio_MIN (sdl->decr, live); sdl->decr -=3D decr; =20 -#if USE_SEMAPHORE - sdl->live =3D live - decr; - hw->rpos =3D sdl->rpos; -#else sdl->live =3D live; -#endif =20 - if (sdl->live > 0) { - sdl_unlock_and_post (s, "sdl_run_out"); - } - else { - sdl_unlock (s, "sdl_run_out"); - } + SDL_UnlockAudio(); + return decr; } =20 @@ -449,23 +335,6 @@ static void *sdl_audio_init (void) return NULL; } =20 -#if USE_SEMAPHORE - s->mutex =3D SDL_CreateMutex (); - if (!s->mutex) { - sdl_logerr ("Failed to create SDL mutex\n"); - SDL_QuitSubSystem (SDL_INIT_AUDIO); - return NULL; - } - - s->sem =3D SDL_CreateSemaphore (0); - if (!s->sem) { - sdl_logerr ("Failed to create SDL semaphore\n"); - SDL_DestroyMutex (s->mutex); - SDL_QuitSubSystem (SDL_INIT_AUDIO); - return NULL; - } -#endif - s->driver_created =3D true; return s; } @@ -474,10 +343,6 @@ static void sdl_audio_fini (void *opaque) { SDLAudioState *s =3D opaque; sdl_close (s); -#if USE_SEMAPHORE - SDL_DestroySemaphore (s->sem); - SDL_DestroyMutex (s->mutex); -#endif SDL_QuitSubSystem (SDL_INIT_AUDIO); s->driver_created =3D false; } --=20 1.8.3.1 From nobody Mon May 6 23:52:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 154933673438020.472832939434852; Mon, 4 Feb 2019 19:18:54 -0800 (PST) Received: from localhost ([127.0.0.1]:53231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrG6-0008Ux-UJ for importer@patchew.org; Mon, 04 Feb 2019 22:18:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrEM-0007aV-Nv for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:17:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqr6L-0002c9-GJ for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:08:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38250) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqr6L-0002b5-8t; Mon, 04 Feb 2019 22:08:45 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3C378666F; Tue, 5 Feb 2019 03:08:36 +0000 (UTC) Received: from thuth.com (ovpn-116-65.phx2.redhat.com [10.3.116.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D64B60CCE; Tue, 5 Feb 2019 03:08:35 +0000 (UTC) From: Thomas Huth To: Gerd Hoffmann , qemu-devel@nongnu.org Date: Tue, 5 Feb 2019 04:08:21 +0100 Message-Id: <1549336101-17623-3-git-send-email-thuth@redhat.com> In-Reply-To: <1549336101-17623-1-git-send-email-thuth@redhat.com> References: <1549336101-17623-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 05 Feb 2019 03:08:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] audio/sdlaudio: Simplify the sdl_callback function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=20Zolt=C3=A1n?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" At the end of the while-loop, either "samples" or "sdl->live" is zero, so now that we've removed the semaphore code, the content of the while-loop is always only executed once. Thus we can remove the while-loop now to get rid of one indentation level here. Signed-off-by: Thomas Huth --- audio/sdlaudio.c | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c index 53bfdbf..f7ee70b 100644 --- a/audio/sdlaudio.c +++ b/audio/sdlaudio.c @@ -189,37 +189,30 @@ static void sdl_callback (void *opaque, Uint8 *buf, i= nt len) SDLAudioState *s =3D &glob_sdl; HWVoiceOut *hw =3D &sdl->hw; int samples =3D len >> hw->info.shift; + int to_mix, decr; =20 - if (s->exit) { + if (s->exit || !sdl->live) { return; } =20 - while (samples) { - int to_mix, decr; - - /* dolog ("in callback samples=3D%d\n", samples); */ - - if (s->exit || !sdl->live) { - break; - } - - /* dolog ("in callback live=3D%d\n", live); */ - to_mix =3D audio_MIN (samples, sdl->live); - decr =3D to_mix; - while (to_mix) { - int chunk =3D audio_MIN (to_mix, hw->samples - hw->rpos); - struct st_sample *src =3D hw->mix_buf + hw->rpos; - - /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk);= */ - hw->clip (buf, src, chunk); - hw->rpos =3D (hw->rpos + chunk) % hw->samples; - to_mix -=3D chunk; - buf +=3D chunk << hw->info.shift; - } - samples -=3D decr; - sdl->live -=3D decr; - sdl->decr +=3D decr; + /* dolog ("in callback samples=3D%d live=3D%d\n", samples, sdl->live);= */ + + to_mix =3D audio_MIN(samples, sdl->live); + decr =3D to_mix; + while (to_mix) { + int chunk =3D audio_MIN(to_mix, hw->samples - hw->rpos); + struct st_sample *src =3D hw->mix_buf + hw->rpos; + + /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */ + hw->clip(buf, src, chunk); + hw->rpos =3D (hw->rpos + chunk) % hw->samples; + to_mix -=3D chunk; + buf +=3D chunk << hw->info.shift; } + samples -=3D decr; + sdl->live -=3D decr; + sdl->decr +=3D decr; + /* dolog ("done len=3D%d\n", len); */ =20 /* SDL2 does not clear the remaining buffer for us, so do it on our ow= n */ --=20 1.8.3.1