qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 6/6] audio: Switch coreaudio to QemuMutex


From: Jan Kiszka
Subject: [Qemu-devel] [PATCH 6/6] audio: Switch coreaudio to QemuMutex
Date: Tue, 20 Sep 2011 18:53:13 +0200

Using the error management of QemuMutex allows to simplify the code.

CC: malc <address@hidden>
CC: Andreas Färber <address@hidden>
Signed-off-by: Jan Kiszka <address@hidden>
---
 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 <CoreAudio/CoreAudio.h>
 #include <string.h>             /* strerror */
-#include <pthread.h>            /* 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, ...)
-- 
1.7.3.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]