1 #include "qemu-common.h"
4 #define AUDIO_CAP "audio-pt"
7 #include "audio_pt_int.h"
9 static void logerr (struct audio_pt
*pt
, int err
, const char *fmt
, ...)
14 AUD_vlog (pt
->drv
, fmt
, ap
);
18 AUD_log (pt
->drv
, "Reason: %s\n", strerror (err
));
21 int audio_pt_init (struct audio_pt
*p
, void *(*func
) (void *),
22 void *opaque
, const char *drv
, const char *cap
)
29 err
= pthread_mutex_init (&p
->mutex
, NULL
);
31 efunc
= "pthread_mutex_init";
35 err
= pthread_cond_init (&p
->cond
, NULL
);
37 efunc
= "pthread_cond_init";
41 err
= pthread_create (&p
->thread
, NULL
, func
, opaque
);
43 efunc
= "pthread_create";
50 err2
= pthread_cond_destroy (&p
->cond
);
52 logerr (p
, err2
, "%s(%s): pthread_cond_destroy failed", cap
, AUDIO_FUNC
);
56 err2
= pthread_mutex_destroy (&p
->mutex
);
58 logerr (p
, err2
, "%s(%s): pthread_mutex_destroy failed", cap
, AUDIO_FUNC
);
62 logerr (p
, err
, "%s(%s): %s failed", cap
, AUDIO_FUNC
, efunc
);
66 int audio_pt_fini (struct audio_pt
*p
, const char *cap
)
70 err
= pthread_cond_destroy (&p
->cond
);
72 logerr (p
, err
, "%s(%s): pthread_cond_destroy failed", cap
, AUDIO_FUNC
);
76 err
= pthread_mutex_destroy (&p
->mutex
);
78 logerr (p
, err
, "%s(%s): pthread_mutex_destroy failed", cap
, AUDIO_FUNC
);
84 int audio_pt_lock (struct audio_pt
*p
, const char *cap
)
88 err
= pthread_mutex_lock (&p
->mutex
);
90 logerr (p
, err
, "%s(%s): pthread_mutex_lock failed", cap
, AUDIO_FUNC
);
96 int audio_pt_unlock (struct audio_pt
*p
, const char *cap
)
100 err
= pthread_mutex_unlock (&p
->mutex
);
102 logerr (p
, err
, "%s(%s): pthread_mutex_unlock failed", cap
, AUDIO_FUNC
);
108 int audio_pt_wait (struct audio_pt
*p
, const char *cap
)
112 err
= pthread_cond_wait (&p
->cond
, &p
->mutex
);
114 logerr (p
, err
, "%s(%s): pthread_cond_wait failed", cap
, AUDIO_FUNC
);
120 int audio_pt_unlock_and_signal (struct audio_pt
*p
, const char *cap
)
124 err
= pthread_mutex_unlock (&p
->mutex
);
126 logerr (p
, err
, "%s(%s): pthread_mutex_unlock failed", cap
, AUDIO_FUNC
);
129 err
= pthread_cond_signal (&p
->cond
);
131 logerr (p
, err
, "%s(%s): pthread_cond_signal failed", cap
, AUDIO_FUNC
);
137 int audio_pt_join (struct audio_pt
*p
, void **arg
, const char *cap
)
142 err
= pthread_join (p
->thread
, &ret
);
144 logerr (p
, err
, "%s(%s): pthread_join failed", cap
, AUDIO_FUNC
);