2
0
Эх сурвалжийг харах

terminate correctly statically created tasks

philippe44 5 жил өмнө
parent
commit
0f8bd30544

+ 2 - 4
components/raop/raop.c

@@ -185,9 +185,6 @@ struct raop_ctx_s *raop_create(struct in_addr host, char *name,
 	LOG_INFO("starting mDNS with %s", id);
 	ESP_ERROR_CHECK( mdns_service_add(id, "_raop", "_tcp", ctx->port, txt, sizeof(txt) / sizeof(mdns_txt_item_t)) );
 	
-	/*
-	xTaskCreate((TaskFunction_t) rtsp_thread, "RTSP_thread", 8*1024, ctx, ESP_TASK_PRIO_MIN + 1, &ctx->thread);
-	*/
     ctx->xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
     ctx->xStack = (StackType_t*) malloc(RTSP_STACK_SIZE);
 	ctx->thread = xTaskCreateStatic( (TaskFunction_t) rtsp_thread, "RTSP_thread", RTSP_STACK_SIZE, ctx, ESP_TASK_PRIO_MIN + 1, ctx->xStack, ctx->xTaskBuffer);
@@ -221,6 +218,7 @@ void raop_delete(struct raop_ctx_s *ctx) {
 	pthread_join(ctx->thread, NULL);
 #else
 	xTaskNotifyWait(0, 0, NULL, portMAX_DELAY);
+	vTaskDelete(ctx->thread);
 	free(ctx->xStack);
 	heap_caps_free(ctx->xTaskBuffer);
 #endif
@@ -369,7 +367,7 @@ static void *rtsp_thread(void *arg) {
 
 #ifndef WIN32
 	xTaskNotify(ctx->joiner, 0, eNoAction);
-	vTaskDelete(NULL);
+	vTaskSuspend(NULL);
 #endif
 
 	return NULL;

+ 2 - 1
components/raop/rtp.c

@@ -305,6 +305,7 @@ void rtp_end(rtp_t *ctx)
 		pthread_join(ctx->thread, NULL);
 #else
 		xTaskNotifyWait(0, 0, NULL, portMAX_DELAY);
+		vTaskDelete(ctx->thread);
 		free(ctx->xStack);
 		heap_caps_free(ctx->xTaskBuffer);
 #endif
@@ -709,7 +710,7 @@ static void *rtp_thread_func(void *arg) {
 
 #ifndef WIN32
 	xTaskNotify(ctx->joiner, 0, eNoAction);
-	vTaskDelete(NULL);
+	vTaskSuspend(NULL);
 #endif
 
 	return NULL;

+ 4 - 0
components/squeezelite/decode_external.c

@@ -35,6 +35,10 @@ extern struct buffer *outputbuf;
 // this is the only system-wide loglevel variable
 extern log_level loglevel;
 
+// not great to have these here, but they should not be in embedded.h
+bool enable_bt_sink;
+bool enable_airplay;
+
 #define RAOP_OUTPUT_SIZE (RAOP_SAMPLE_RATE * 2 * 2 * 2 * 1.2)
 
 static raop_event_t	raop_state;

+ 3 - 5
components/squeezelite/embedded.h

@@ -1,6 +1,6 @@
 #ifndef EMBEDDED_H
 #define EMBEDDED_H
-#include "esp_system.h"
+
 #include <inttypes.h>
 
 /* 	must provide 
@@ -8,6 +8,7 @@
 		- pthread_create_name
 		- stack size
 		- s16_t, s32_t, s64_t and u64_t
+		- EXT_BSS 
 	can overload (use #define)
 		- exit
 		- gettime_ms
@@ -25,6 +26,7 @@
 #define IR_THREAD_STACK_SIZE      6 * 1024
 
 //#define BASE_CAP "Model=squeezelite,AccuratePlayPoints=0,HasDigitalOut=1,HasPolarityInversion=1,Firmware=" VERSION	
+#define EXT_BSS __attribute__((section(".ext_ram.bss"))) 
 
 typedef int16_t   s16_t;
 typedef int32_t   s32_t;
@@ -41,10 +43,6 @@ uint32_t 	_gettime_ms_(void);
 int			pthread_create_name(pthread_t *thread, _CONST pthread_attr_t  *attr, 
 				   void *(*start_routine)( void * ), void *arg, char *name);
 			
-// these are here as they can be #define to nothing
-extern bool enable_bt_sink;
-extern bool enable_airplay;
-
 void 		register_external(void);
 void 		deregister_external(void);
 				   

+ 2 - 7
components/squeezelite/slimproto.c

@@ -533,7 +533,7 @@ static void process(u8_t *pack, int len) {
 static bool running;
 
 static void slimproto_run() {
-	static u8_t *buffer = NULL;
+	static u8_t EXT_BSS buffer[MAXBUF];
 	int  expect = 0;
 	int  got    = 0;
 	u32_t now;
@@ -541,9 +541,6 @@ static void slimproto_run() {
 	event_handle ehandles[2];
 	int timeouts = 0;
 	
-	// just to avoid having to free that up at multiple places
-	if (!buffer) buffer = malloc(MAXBUF);
-
 	set_readwake_handles(ehandles, sock, wake_e);
 
 	while (running && !new_server) {
@@ -626,14 +623,12 @@ static void slimproto_run() {
 			bool _start_output = false;
 			decode_state _decode_state;
 			disconnect_code disconnect_code;
-			static char *header = NULL;
+			static char EXT_BSS header[MAX_HEADER];
 			size_t header_len = 0;
 #if IR
 			bool _sendIR   = false;
 			u32_t ir_code, ir_ts;
 #endif
-			// just to avoid allocating it at every pass
-			if (!header) header = malloc(MAX_HEADER);
 			
 			last = now;