1 #include "qemu/osdep.h"
4 #define AUDIO_CAP "audio-pt"
7 #include "audio_pt_int.h"
9 static void GCC_FMT_ATTR(3, 4) logerr (struct audio_pt
*pt
, int err
,
15 AUD_vlog (pt
->drv
, fmt
, ap
);
19 AUD_log (pt
->drv
, "Reason: %s\n", strerror (err
));
22 int audio_pt_init (struct audio_pt
*p
, void *(*func
) (void *),
23 void *opaque
, const char *drv
, const char *cap
)
27 sigset_t set
, old_set
;
31 err
= sigfillset (&set
);
33 logerr(p
, errno
, "%s(%s): sigfillset failed", cap
, __func__
);
37 err
= pthread_mutex_init (&p
->mutex
, NULL
);
39 efunc
= "pthread_mutex_init";
43 err
= pthread_cond_init (&p
->cond
, NULL
);
45 efunc
= "pthread_cond_init";
49 err
= pthread_sigmask (SIG_BLOCK
, &set
, &old_set
);
51 efunc
= "pthread_sigmask";
55 err
= pthread_create (&p
->thread
, NULL
, func
, opaque
);
57 err2
= pthread_sigmask (SIG_SETMASK
, &old_set
, NULL
);
59 logerr(p
, err2
, "%s(%s): pthread_sigmask (restore) failed",
61 /* We have failed to restore original signal mask, all bets are off,
62 so terminate the process */
67 efunc
= "pthread_create";
74 err2
= pthread_cond_destroy (&p
->cond
);
76 logerr(p
, err2
, "%s(%s): pthread_cond_destroy failed", cap
, __func__
);
80 err2
= pthread_mutex_destroy (&p
->mutex
);
82 logerr(p
, err2
, "%s(%s): pthread_mutex_destroy failed", cap
, __func__
);
86 logerr(p
, err
, "%s(%s): %s failed", cap
, __func__
, efunc
);
90 int audio_pt_fini (struct audio_pt
*p
, const char *cap
)
94 err
= pthread_cond_destroy (&p
->cond
);
96 logerr(p
, err
, "%s(%s): pthread_cond_destroy failed", cap
, __func__
);
100 err
= pthread_mutex_destroy (&p
->mutex
);
102 logerr(p
, err
, "%s(%s): pthread_mutex_destroy failed", cap
, __func__
);
108 int audio_pt_lock (struct audio_pt
*p
, const char *cap
)
112 err
= pthread_mutex_lock (&p
->mutex
);
114 logerr(p
, err
, "%s(%s): pthread_mutex_lock failed", cap
, __func__
);
120 int audio_pt_unlock (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
, __func__
);
132 int audio_pt_wait (struct audio_pt
*p
, const char *cap
)
136 err
= pthread_cond_wait (&p
->cond
, &p
->mutex
);
138 logerr(p
, err
, "%s(%s): pthread_cond_wait failed", cap
, __func__
);
144 int audio_pt_unlock_and_signal (struct audio_pt
*p
, const char *cap
)
148 err
= pthread_mutex_unlock (&p
->mutex
);
150 logerr(p
, err
, "%s(%s): pthread_mutex_unlock failed", cap
, __func__
);
153 err
= pthread_cond_signal (&p
->cond
);
155 logerr(p
, err
, "%s(%s): pthread_cond_signal failed", cap
, __func__
);
161 int audio_pt_join (struct audio_pt
*p
, void **arg
, const char *cap
)
166 err
= pthread_join (p
->thread
, &ret
);
168 logerr(p
, err
, "%s(%s): pthread_join failed", cap
, __func__
);