mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 12:37:01 +03:00
thread naming correction + change embedded.h logic
This commit is contained in:
@@ -206,11 +206,8 @@ void decode_init(log_level level, const char *include_codecs, const char *exclud
|
|||||||
#ifdef PTHREAD_STACK_MIN
|
#ifdef PTHREAD_STACK_MIN
|
||||||
pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + DECODE_THREAD_STACK_SIZE);
|
pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + DECODE_THREAD_STACK_SIZE);
|
||||||
#endif
|
#endif
|
||||||
pthread_create(&thread, &attr, decode_thread, NULL);
|
pthread_create_name(&thread, &attr, decode_thread, NULL, "decode");
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
#if HAS_PTHREAD_SETNAME_NP
|
|
||||||
pthread_setname_np(thread, "decode");
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
#if WIN
|
#if WIN
|
||||||
thread = CreateThread(NULL, DECODE_THREAD_STACK_SIZE, (LPTHREAD_START_ROUTINE)&decode_thread, NULL, 0, NULL);
|
thread = CreateThread(NULL, DECODE_THREAD_STACK_SIZE, (LPTHREAD_START_ROUTINE)&decode_thread, NULL, 0, NULL);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "squeezelite.h"
|
#include "squeezelite.h"
|
||||||
|
#include "pthread.h"
|
||||||
#include "esp_pthread.h"
|
#include "esp_pthread.h"
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
|
|
||||||
@@ -34,11 +35,11 @@ void *audio_calloc(size_t nmemb, size_t size) {
|
|||||||
return calloc(nmemb, 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();
|
esp_pthread_cfg_t cfg = esp_pthread_get_default_config();
|
||||||
cfg.thread_name= name;
|
cfg.thread_name = name;
|
||||||
cfg.inherit_cfg = true;
|
cfg.inherit_cfg = true;
|
||||||
return esp_pthread_set_cfg(&cfg);
|
esp_pthread_set_cfg(&cfg);
|
||||||
|
return pthread_create(thread, attr, start_routine, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,15 @@
|
|||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#define HAS_MUTEX_CREATE_P 0
|
/* must provide
|
||||||
#define HAS_PTHREAD_SETNAME_NP 1
|
- 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
|
#ifndef PTHREAD_STACK_MIN
|
||||||
#define PTHREAD_STACK_MIN 256
|
#define PTHREAD_STACK_MIN 256
|
||||||
@@ -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)
|
// all exit() calls are made from main thread (or a function called in main thread)
|
||||||
#define exit(code) { int ret = code; pthread_exit(&ret); }
|
#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
|
#endif // EMBEDDED_H
|
||||||
|
|||||||
@@ -149,17 +149,11 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
|
|||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + OUTPUT_THREAD_STACK_SIZE);
|
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);
|
pthread_attr_destroy(&attr);
|
||||||
#if HAS_PTHREAD_SETNAME_NP
|
|
||||||
pthread_setname_np(thread, "output_i2s");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// leave stack size to default
|
// leave stack size to default
|
||||||
pthread_create(&stats_thread, NULL, output_thread_i2s_stats, NULL);
|
pthread_create_name(&stats_thread, NULL, output_thread_i2s_stats, NULL, "output_i2s_sts");
|
||||||
#if HAS_PTHREAD_SETNAME_NP
|
|
||||||
pthread_setname_np(stats_thread, "output_i2s_sts");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -286,6 +280,8 @@ static void *output_thread_i2s() {
|
|||||||
SET_MIN_MAX( TIME_MEASUREMENT_GET(timer_start),i2s_time);
|
SET_MIN_MAX( TIME_MEASUREMENT_GET(timer_start),i2s_time);
|
||||||
|
|
||||||
frames = 0;
|
frames = 0;
|
||||||
|
} else {
|
||||||
|
LOG_WARN("no frame returned %d", output.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -315,15 +315,16 @@ typedef int64_t s64_t;
|
|||||||
|
|
||||||
#define mutex_type pthread_mutex_t
|
#define mutex_type pthread_mutex_t
|
||||||
#define mutex_create(m) pthread_mutex_init(&m, NULL)
|
#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)
|
#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
|
#endif
|
||||||
#define mutex_lock(m) pthread_mutex_lock(&m)
|
#define mutex_lock(m) pthread_mutex_lock(&m)
|
||||||
#define mutex_unlock(m) pthread_mutex_unlock(&m)
|
#define mutex_unlock(m) pthread_mutex_unlock(&m)
|
||||||
#define mutex_destroy(m) pthread_mutex_destroy(&m)
|
#define mutex_destroy(m) pthread_mutex_destroy(&m)
|
||||||
#define thread_type pthread_t
|
#define thread_type pthread_t
|
||||||
|
#if !EMBEDDED
|
||||||
|
#define pthread_create_name(t,a,f,p,n) pthread_create(t,a,f,p)
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if WIN
|
#if WIN
|
||||||
|
|||||||
@@ -412,11 +412,8 @@ void stream_init(log_level level, unsigned stream_buf_size) {
|
|||||||
#ifdef PTHREAD_STACK_MIN
|
#ifdef PTHREAD_STACK_MIN
|
||||||
pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + STREAM_THREAD_STACK_SIZE);
|
pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + STREAM_THREAD_STACK_SIZE);
|
||||||
#endif
|
#endif
|
||||||
pthread_create(&thread, &attr, stream_thread, NULL);
|
pthread_create_name(&thread, &attr, stream_thread, NULL, "stream");
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
#if HAS_PTHREAD_SETNAME_NP
|
|
||||||
pthread_setname_np(thread, "stream");
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
#if WIN
|
#if WIN
|
||||||
thread = CreateThread(NULL, STREAM_THREAD_STACK_SIZE, (LPTHREAD_START_ROUTINE)&stream_thread, NULL, 0, NULL);
|
thread = CreateThread(NULL, STREAM_THREAD_STACK_SIZE, (LPTHREAD_START_ROUTINE)&stream_thread, NULL, 0, NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user