diff --git a/components/squeezelite/decode.c b/components/squeezelite/decode.c index 60405e5c..d08e0f47 100644 --- a/components/squeezelite/decode.c +++ b/components/squeezelite/decode.c @@ -206,11 +206,8 @@ void decode_init(log_level level, const char *include_codecs, const char *exclud #ifdef PTHREAD_STACK_MIN pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + DECODE_THREAD_STACK_SIZE); #endif - pthread_create(&thread, &attr, decode_thread, NULL); + pthread_create_name(&thread, &attr, decode_thread, NULL, "decode"); pthread_attr_destroy(&attr); -#if HAS_PTHREAD_SETNAME_NP - pthread_setname_np(thread, "decode"); -#endif #endif #if WIN thread = CreateThread(NULL, DECODE_THREAD_STACK_SIZE, (LPTHREAD_START_ROUTINE)&decode_thread, NULL, 0, NULL); diff --git a/components/squeezelite/embedded.c b/components/squeezelite/embedded.c index cfaf76f8..a5b4b474 100644 --- a/components/squeezelite/embedded.c +++ b/components/squeezelite/embedded.c @@ -19,6 +19,7 @@ * */ #include "squeezelite.h" +#include "pthread.h" #include "esp_pthread.h" #include "esp_system.h" @@ -34,11 +35,11 @@ void *audio_calloc(size_t nmemb, size_t size) { return calloc(nmemb, size); } -int pthread_setname_np(pthread_t thread, const char *name) { +int pthread_create_name(pthread_t *thread, _CONST pthread_attr_t *attr, + void *(*start_routine)( void * ), void *arg, char *name) { esp_pthread_cfg_t cfg = esp_pthread_get_default_config(); - cfg.thread_name= name; + cfg.thread_name = name; cfg.inherit_cfg = true; - return esp_pthread_set_cfg(&cfg); + esp_pthread_set_cfg(&cfg); + return pthread_create(thread, attr, start_routine, arg); } - - diff --git a/components/squeezelite/embedded.h b/components/squeezelite/embedded.h index 264d50c8..8b30e2e4 100644 --- a/components/squeezelite/embedded.h +++ b/components/squeezelite/embedded.h @@ -3,9 +3,16 @@ #include -#define HAS_MUTEX_CREATE_P 0 -#define HAS_PTHREAD_SETNAME_NP 1 - +/* must provide + - mutex_create_p + - pthread_create_name + - stack size + - s16_t, s32_t, s64_t and u64_t + can overload + - exit + recommended to add platform specific include(s) here +*/ + #ifndef PTHREAD_STACK_MIN #define PTHREAD_STACK_MIN 256 #endif @@ -23,6 +30,9 @@ typedef unsigned long long u64_t; // all exit() calls are made from main thread (or a function called in main thread) #define exit(code) { int ret = code; pthread_exit(&ret); } -int pthread_setname_np(pthread_t thread, const char *name); +#define mutex_create_p(m) mutex_create(m) + +int pthread_create_name(pthread_t *thread, _CONST pthread_attr_t *attr, + void *(*start_routine)( void * ), void *arg, char *name); #endif // EMBEDDED_H diff --git a/components/squeezelite/output_i2s.c b/components/squeezelite/output_i2s.c index 8f10788f..18dbafcf 100644 --- a/components/squeezelite/output_i2s.c +++ b/components/squeezelite/output_i2s.c @@ -149,17 +149,11 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + OUTPUT_THREAD_STACK_SIZE); - pthread_create(&thread, &attr, output_thread_i2s, NULL); + pthread_create_name(&thread, &attr, output_thread_i2s, NULL, "output_i2s"); pthread_attr_destroy(&attr); -#if HAS_PTHREAD_SETNAME_NP - pthread_setname_np(thread, "output_i2s"); -#endif // leave stack size to default - pthread_create(&stats_thread, NULL, output_thread_i2s_stats, NULL); -#if HAS_PTHREAD_SETNAME_NP - pthread_setname_np(stats_thread, "output_i2s_sts"); -#endif + pthread_create_name(&stats_thread, NULL, output_thread_i2s_stats, NULL, "output_i2s_sts"); } @@ -286,7 +280,9 @@ static void *output_thread_i2s() { SET_MIN_MAX( TIME_MEASUREMENT_GET(timer_start),i2s_time); frames = 0; - } + } else { + LOG_WARN("no frame returned %d", output.state); + } } return 0; diff --git a/components/squeezelite/squeezelite.h b/components/squeezelite/squeezelite.h index 153114ce..2e9aaeee 100644 --- a/components/squeezelite/squeezelite.h +++ b/components/squeezelite/squeezelite.h @@ -315,15 +315,16 @@ typedef int64_t s64_t; #define mutex_type pthread_mutex_t #define mutex_create(m) pthread_mutex_init(&m, NULL) -#if HAS_MUTEX_CREATE_P +#if !EMBEDDED #define mutex_create_p(m) pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT); pthread_mutex_init(&m, &attr); pthread_mutexattr_destroy(&attr) -#else -#define mutex_create_p(m) mutex_create(m) #endif #define mutex_lock(m) pthread_mutex_lock(&m) #define mutex_unlock(m) pthread_mutex_unlock(&m) #define mutex_destroy(m) pthread_mutex_destroy(&m) #define thread_type pthread_t +#if !EMBEDDED +#define pthread_create_name(t,a,f,p,n) pthread_create(t,a,f,p) +#endif #endif #if WIN diff --git a/components/squeezelite/stream.c b/components/squeezelite/stream.c index 59f9f693..547f8b6c 100644 --- a/components/squeezelite/stream.c +++ b/components/squeezelite/stream.c @@ -412,11 +412,8 @@ void stream_init(log_level level, unsigned stream_buf_size) { #ifdef PTHREAD_STACK_MIN pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + STREAM_THREAD_STACK_SIZE); #endif - pthread_create(&thread, &attr, stream_thread, NULL); + pthread_create_name(&thread, &attr, stream_thread, NULL, "stream"); pthread_attr_destroy(&attr); -#if HAS_PTHREAD_SETNAME_NP - pthread_setname_np(thread, "stream"); -#endif #endif #if WIN thread = CreateThread(NULL, STREAM_THREAD_STACK_SIZE, (LPTHREAD_START_ROUTINE)&stream_thread, NULL, 0, NULL);