diff --git a/platforms/common/include/px4_platform_common/app.h b/platforms/common/include/px4_platform_common/app.h index bb2b923d3f0..0f8e2b13beb 100644 --- a/platforms/common/include/px4_platform_common/app.h +++ b/platforms/common/include/px4_platform_common/app.h @@ -40,6 +40,8 @@ #pragma once +#include + namespace px4 { @@ -48,17 +50,17 @@ class AppState public: ~AppState() {} - AppState() : _exitRequested(false), _isRunning(false) {} + AppState() {} - bool exitRequested() { return _exitRequested; } - void requestExit() { _exitRequested = true; } + bool exitRequested() { return _exitRequested.load(); } + void requestExit() { _exitRequested.store(true); } - bool isRunning() { return _isRunning; } - void setRunning(bool running) { _isRunning = running; } + bool isRunning() { return _isRunning.load(); } + void setRunning(bool running) { _isRunning.store(running); } protected: - bool _exitRequested; - bool _isRunning; + px4::atomic_bool _exitRequested{false}; + px4::atomic_bool _isRunning{false}; private: AppState(const AppState &); const AppState &operator=(const AppState &); diff --git a/platforms/nuttx/src/px4/common/tasks.cpp b/platforms/nuttx/src/px4/common/tasks.cpp index 9ad860dc182..bffb270e264 100644 --- a/platforms/nuttx/src/px4/common/tasks.cpp +++ b/platforms/nuttx/src/px4/common/tasks.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -91,6 +92,16 @@ int px4_task_delete(int pid) return task_delete(pid); } +int px4_task_join(int pid) +{ + // Wait for the task to exit by polling whether it still exists + while (kill(pid, 0) == 0) { + px4_usleep(10000); + } + + return 0; +} + const char *px4_get_taskname(void) { #if CONFIG_TASK_NAME_SIZE > 0 && (defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT))