From e11d26881895d7d6e3814dac5aa325ec121981fc Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Tue, 10 Jul 2018 15:07:00 -0700 Subject: [PATCH] AP_HAL_Linux: Thread: allow loose running thread --- libraries/AP_HAL_Linux/Thread.cpp | 4 ++++ libraries/AP_HAL_Linux/Thread.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/libraries/AP_HAL_Linux/Thread.cpp b/libraries/AP_HAL_Linux/Thread.cpp index 3350372a8c..91fcfcbbb4 100644 --- a/libraries/AP_HAL_Linux/Thread.cpp +++ b/libraries/AP_HAL_Linux/Thread.cpp @@ -40,6 +40,10 @@ void *Thread::_run_trampoline(void *arg) thread->_poison_stack(); thread->_run(); + if (thread->_auto_free) { + delete thread; + } + return nullptr; } diff --git a/libraries/AP_HAL_Linux/Thread.h b/libraries/AP_HAL_Linux/Thread.h index 36995dbe0b..6652d24466 100644 --- a/libraries/AP_HAL_Linux/Thread.h +++ b/libraries/AP_HAL_Linux/Thread.h @@ -45,6 +45,8 @@ public: bool set_stack_size(size_t stack_size); + void set_auto_free(bool auto_free) { _auto_free = auto_free; } + virtual bool stop() { return false; } bool join(); @@ -64,6 +66,7 @@ protected: task_t _task; bool _started = false; bool _should_exit = false; + bool _auto_free = false; pthread_t _ctx = 0; struct stack_debug {