From ecf6b7aa60af1807add966fe0dde195923c05cd5 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Thu, 14 May 2020 22:57:27 +0000
Subject: [PATCH] xptone_open() is also a valid first call... put the
 pthread_once() in there as well. Fixes https://sf.net/p/syncterm/tickets/14/
 and https://sf.net/p/syncterm/tickets/16/

---
 src/xpdev/xpbeep.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/xpdev/xpbeep.c b/src/xpdev/xpbeep.c
index 7f2a429c3f..70f7aa78b8 100644
--- a/src/xpdev/xpbeep.c
+++ b/src/xpdev/xpbeep.c
@@ -210,6 +210,8 @@ struct alsa_api_struct {
 struct alsa_api_struct *alsa_api=NULL;
 #endif
 
+static void init_sample(void);
+
 /********************************************************************************/
 /* Calculate and generate a sound wave pattern (thanks to Deuce!)				*/
 /********************************************************************************/
@@ -364,6 +366,7 @@ void DLLCALL sdl_fillbuf(void *userdata, Uint8 *stream, int len)
 }
 #endif
 
+pthread_once_t sample_initialized_pto = PTHREAD_ONCE_INIT;
 static BOOL
 DLLCALL xptone_open_locked(void)
 {
@@ -649,6 +652,7 @@ DLLCALL xptone_open(void)
 {
 	BOOL ret;
 #ifdef XPDEV_THREAD_SAFE
+	pthread_once(&sample_initialized_pto, init_sample);
 	pthread_mutex_lock(&handle_mutex);
 #endif
 	ret = xptone_open_locked();
@@ -1048,8 +1052,7 @@ error_return:
 	sample_thread_running=FALSE;
 }
 
-pthread_once_t sample_initialized_pto = PTHREAD_ONCE_INIT;
-void
+static void
 init_sample(void)
 {
 	pthread_mutex_init(&sample_mutex, NULL);
-- 
GitLab