Skip to content

Commit 33a1d3a

Browse files
committed
use initializers so mutex and cond are always valid
1 parent ecacbe6 commit 33a1d3a

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

lib/gamepad/audio.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
static unsigned char queued_audio[8192];
2121
static size_t queued_audio_start = 0;
2222
static size_t queued_audio_end = 0;
23-
static pthread_mutex_t queued_audio_mutex;
24-
static pthread_cond_t queued_audio_cond;
23+
static pthread_mutex_t queued_audio_mutex = PTHREAD_MUTEX_INITIALIZER;
24+
static pthread_cond_t queued_audio_cond = PTHREAD_COND_INITIALIZER;
2525

2626
int send_audio_packet(const void *data, size_t len)
2727
{
@@ -173,9 +173,6 @@ void *listen_audio(void *x)
173173
queued_audio_start = 0;
174174
queued_audio_end = 0;
175175

176-
pthread_mutex_init(&queued_audio_mutex, 0);
177-
pthread_cond_init(&queued_audio_cond, 0);
178-
179176
pthread_t mic_thread;
180177
int mic_thread_created = 1;
181178
if (pthread_create(&mic_thread, 0, handle_queued_audio, info) != 0) {
@@ -198,9 +195,6 @@ void *listen_audio(void *x)
198195
pthread_join(mic_thread, 0);
199196
}
200197

201-
pthread_cond_destroy(&queued_audio_cond);
202-
pthread_mutex_destroy(&queued_audio_mutex);
203-
204198
pthread_exit(NULL);
205199

206200
return NULL;

0 commit comments

Comments
 (0)