From patchwork Tue Sep 20 16:53:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 115605 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 99606B70CA for ; Wed, 21 Sep 2011 02:53:44 +1000 (EST) Received: from localhost ([::1]:46495 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R63Zd-00087w-4n for incoming@patchwork.ozlabs.org; Tue, 20 Sep 2011 12:53:33 -0400 Received: from eggs.gnu.org ([140.186.70.92]:58624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R63ZQ-0007xp-62 for qemu-devel@nongnu.org; Tue, 20 Sep 2011 12:53:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R63ZN-0000x1-I9 for qemu-devel@nongnu.org; Tue, 20 Sep 2011 12:53:20 -0400 Received: from thoth.sbs.de ([192.35.17.2]:17250) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R63ZN-0000ws-8I for qemu-devel@nongnu.org; Tue, 20 Sep 2011 12:53:17 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.13.6/8.13.6) with ESMTP id p8KGrE40020616; Tue, 20 Sep 2011 18:53:14 +0200 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id p8KGrDYt003984; Tue, 20 Sep 2011 18:53:14 +0200 From: Jan Kiszka To: Anthony Liguori , qemu-devel@nongnu.org Date: Tue, 20 Sep 2011 18:53:13 +0200 Message-Id: <55cdae9265253263fb7dbc883d3297e52b13763f.1316537591.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by thoth.sbs.de id p8KGrE40020616 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 192.35.17.2 Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH 6/6] audio: Switch coreaudio to QemuMutex X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Using the error management of QemuMutex allows to simplify the code. CC: malc CC: Andreas Färber Signed-off-by: Jan Kiszka --- audio/coreaudio.c | 56 +++++++--------------------------------------------- 1 files changed, 8 insertions(+), 48 deletions(-) diff --git a/audio/coreaudio.c b/audio/coreaudio.c index 5964c62..c34a593 100644 --- a/audio/coreaudio.c +++ b/audio/coreaudio.c @@ -24,9 +24,9 @@ #include #include /* strerror */ -#include /* pthread_X */ #include "qemu-common.h" +#include "qemu-thread.h" #include "audio.h" #define AUDIO_CAP "coreaudio" @@ -44,7 +44,7 @@ struct { typedef struct coreaudioVoiceOut { HWVoiceOut hw; - pthread_mutex_t mutex; + QemuMutex mutex; int isAtexit; AudioDeviceID outputDeviceID; UInt32 audioDevicePropertyBufferFrameSize; @@ -164,40 +164,12 @@ static void coreaudio_atexit (void) conf.isAtexit = 1; } -static int coreaudio_lock (coreaudioVoiceOut *core, const char *fn_name) -{ - int err; - - err = pthread_mutex_lock (&core->mutex); - if (err) { - dolog ("Could not lock voice for %s\nReason: %s\n", - fn_name, strerror (err)); - return -1; - } - return 0; -} - -static int coreaudio_unlock (coreaudioVoiceOut *core, const char *fn_name) -{ - int err; - - err = pthread_mutex_unlock (&core->mutex); - if (err) { - dolog ("Could not unlock voice for %s\nReason: %s\n", - fn_name, strerror (err)); - return -1; - } - return 0; -} - static int coreaudio_run_out (HWVoiceOut *hw, int live) { int decr; coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; - if (coreaudio_lock (core, "coreaudio_run_out")) { - return 0; - } + qemu_mutex_lock(&core->mutex); if (core->decr > live) { ldebug ("core->decr %d live %d core->live %d\n", @@ -240,10 +212,7 @@ static OSStatus audioDeviceIOProc( #endif #endif - if (coreaudio_lock (core, "audioDeviceIOProc")) { - inInputTime = 0; - return 0; - } + qemu_mutex_lock(&core->mutex); frameCount = core->audioDevicePropertyBufferFrameSize; live = core->live; @@ -251,7 +220,7 @@ static OSStatus audioDeviceIOProc( /* if there are not enough samples, set signal and return */ if (live < frameCount) { inInputTime = 0; - coreaudio_unlock (core, "audioDeviceIOProc(empty)"); + qemu_mutex_unlock(&core->mutex); return 0; } @@ -278,7 +247,7 @@ static OSStatus audioDeviceIOProc( core->decr += frameCount; core->rpos = rpos; - coreaudio_unlock (core, "audioDeviceIOProc"); + qemu_mutex_unlock(&core->mutex); return 0; } @@ -296,12 +265,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as) const char *typ = "playback"; AudioValueRange frameRange; - /* create mutex */ - err = pthread_mutex_init(&core->mutex, NULL); - if (err) { - dolog("Could not create mutex\nReason: %s\n", strerror (err)); - return -1; - } + qemu_mutex_init(&core->mutex); audio_pcm_init_info (&hw->info, as); @@ -461,11 +425,7 @@ static void coreaudio_fini_out (HWVoiceOut *hw) } core->outputDeviceID = kAudioDeviceUnknown; - /* destroy mutex */ - err = pthread_mutex_destroy(&core->mutex); - if (err) { - dolog("Could not destroy mutex\nReason: %s\n", strerror (err)); - } + qemu_mutex_destroy(&core->mutex); } static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)