2 #include "qemu-common.h"
5 #define AUDIO_CAP "audio-pt"
8 #include "audio_pt_int.h"
10 static void GCC_FMT_ATTR(3, 4) logerr (struct audio_pt
*pt
, int err
,
16 AUD_vlog (pt
->drv
, fmt
, ap
);
20 AUD_log (pt
->drv
, "Reason: %s\n", strerror (err
));
23 int audio_pt_init (struct audio_pt
*p
, void *(*func
) (void *),
24 void *opaque
, const char *drv
, const char *cap
)
28 sigset_t set
, old_set
;
32 err
= sigfillset (&set
);
34 logerr (p
, errno
, "%s(%s): sigfillset failed", cap
, AUDIO_FUNC
);
38 err
= pthread_mutex_init (&p
->mutex
, NULL
);
40 efunc
= "pthread_mutex_init";
44 err
= pthread_cond_init (&p
->cond
, NULL
);
46 efunc
= "pthread_cond_init";
50 err
= pthread_sigmask (SIG_BLOCK
, &set
, &old_set
);
52 efunc
= "pthread_sigmask";
56 err
= pthread_create (&p
->thread
, NULL
, func
, opaque
);
58 err2
= pthread_sigmask (SIG_SETMASK
, &old_set
, NULL
);
60 logerr (p
, err2
, "%s(%s): pthread_sigmask (restore) failed",
62 /* We have failed to restore original signal mask, all bets are off,
63 so terminate the process */
68 efunc
= "pthread_create";
75 err2
= pthread_cond_destroy (&p
->cond
);
77 logerr (p
, err2
, "%s(%s): pthread_cond_destroy failed", cap
, AUDIO_FUNC
);
81 err2
= pthread_mutex_destroy (&p
->mutex
);
83 logerr (p
, err2
, "%s(%s): pthread_mutex_destroy failed", cap
, AUDIO_FUNC
);
87 logerr (p
, err
, "%s(%s): %s failed", cap
, AUDIO_FUNC
, efunc
);
91 int audio_pt_fini (struct audio_pt
*p
, const char *cap
)
95 err
= pthread_cond_destroy (&p
->cond
);
97 logerr (p
, err
, "%s(%s): pthread_cond_destroy failed", cap
, AUDIO_FUNC
);
101 err
= pthread_mutex_destroy (&p
->mutex
);
103 logerr (p
, err
, "%s(%s): pthread_mutex_destroy failed", cap
, AUDIO_FUNC
);
109 int audio_pt_lock (struct audio_pt
*p
, const char *cap
)
113 err
= pthread_mutex_lock (&p
->mutex
);
115 logerr (p
, err
, "%s(%s): pthread_mutex_lock failed", cap
, AUDIO_FUNC
);
121 int audio_pt_unlock (struct audio_pt
*p
, const char *cap
)
125 err
= pthread_mutex_unlock (&p
->mutex
);
127 logerr (p
, err
, "%s(%s): pthread_mutex_unlock failed", cap
, AUDIO_FUNC
);
133 int audio_pt_wait (struct audio_pt
*p
, const char *cap
)
137 err
= pthread_cond_wait (&p
->cond
, &p
->mutex
);
139 logerr (p
, err
, "%s(%s): pthread_cond_wait failed", cap
, AUDIO_FUNC
);
145 int audio_pt_unlock_and_signal (struct audio_pt
*p
, const char *cap
)
149 err
= pthread_mutex_unlock (&p
->mutex
);
151 logerr (p
, err
, "%s(%s): pthread_mutex_unlock failed", cap
, AUDIO_FUNC
);
154 err
= pthread_cond_signal (&p
->cond
);
156 logerr (p
, err
, "%s(%s): pthread_cond_signal failed", cap
, AUDIO_FUNC
);
162 int audio_pt_join (struct audio_pt
*p
, void **arg
, const char *cap
)
167 err
= pthread_join (p
->thread
, &ret
);
169 logerr (p
, err
, "%s(%s): pthread_join failed", cap
, AUDIO_FUNC
);