From f7c7ee00e989bdbe170aeedcd228de3800b19cc1 Mon Sep 17 00:00:00 2001
From: Andrew Tridgell <andrew@tridgell.net>
Date: Sat, 20 Jan 2024 07:52:43 +1100
Subject: [PATCH] HAL_ChibiOS: added a delete_next thread field for cleanup

allows for cleanup of web server threads in bootloader
---
 libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h                | 2 ++
 libraries/AP_HAL_ChibiOS/hwdef/include/network_bootloader.inc | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h b/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h
index f673dcc4b9..d71f13ea41 100644
--- a/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h
+++ b/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h
@@ -708,8 +708,10 @@ extern "C" {
  * @brief   Threads descriptor structure extension.
  * @details User fields added to the end of the @p thread_t structure.
  */
+#ifndef CH_CFG_THREAD_EXTRA_FIELDS
 #define CH_CFG_THREAD_EXTRA_FIELDS                                          \
   /* Add threads custom fields here.*/
+#endif
 
 /**
  * @brief   Threads initialization hook.
diff --git a/libraries/AP_HAL_ChibiOS/hwdef/include/network_bootloader.inc b/libraries/AP_HAL_ChibiOS/hwdef/include/network_bootloader.inc
index 67dbc2df63..0703f3397a 100644
--- a/libraries/AP_HAL_ChibiOS/hwdef/include/network_bootloader.inc
+++ b/libraries/AP_HAL_ChibiOS/hwdef/include/network_bootloader.inc
@@ -20,3 +20,5 @@ EXT_FLASH_SIZE_MB 0
 
 # don't combine sdcard bl and network bl
 undef AP_BOOTLOADER_FLASH_FROM_SD_ENABLED
+
+define CH_CFG_THREAD_EXTRA_FIELDS struct ch_thread *delete_next;