Add thread wrapper
Build / Build app and tests (ubuntu-24.04) (push) Failing after 2m32s
Documentation / Build (1.14.0) (push) Failing after 15s
Documentation / Build (1.9.6) (push) Successful in 12s
Documentation / Deploy (push) Has been skipped

This commit is contained in:
2026-04-23 21:37:09 -07:00
parent ae53d7f7f3
commit 7f17e56e34
8 changed files with 82 additions and 23 deletions
+1
View File
@@ -18,6 +18,7 @@ target_sources(app
src/SensorDataProcessor.hpp src/SensorDataProcessor.hpp
src/SensorSampler.cpp src/SensorSampler.cpp
src/SensorSampler.hpp src/SensorSampler.hpp
src/ThreadWrapper.hpp
) )
# The code below locates the git index file for this repository and adds it as a dependency for # The code below locates the git index file for this repository and adds it as a dependency for
+7 -5
View File
@@ -1,9 +1,11 @@
#include "FirmwareManager.hpp" #include "FirmwareManager.hpp"
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
void app::FirmwareManager::entryPoint(void *, void *, void *) { void app::FirmwareManager::init() {}
while (true) {
printk("app::FirmwareManager::entryPoint - Running...\n"); void app::FirmwareManager::run() {
k_sleep(K_SECONDS(5)); printk("app::FirmwareManager::run - Running...\n");
} k_sleep(K_SECONDS(5));
} }
void app::FirmwareManager::finalize() {}
+8 -2
View File
@@ -1,14 +1,20 @@
#ifndef FIRMWARE_MANAGER_HPP #ifndef FIRMWARE_MANAGER_HPP
#define FIRMWARE_MANAGER_HPP #define FIRMWARE_MANAGER_HPP
#include "ThreadWrapper.hpp"
namespace app { namespace app {
class FirmwareManager { class FirmwareManager : public ThreadWrapper<FirmwareManager> {
public: public:
FirmwareManager() = default; FirmwareManager() = default;
~FirmwareManager() = default; ~FirmwareManager() = default;
static void entryPoint(void *, void *, void *); void init();
void run();
void finalize();
private: private:
}; };
+7 -5
View File
@@ -1,9 +1,11 @@
#include "SensorDataProcessor.hpp" #include "SensorDataProcessor.hpp"
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
void app::SensorDataProcessor::entryPoint(void *, void *, void *) { void app::SensorDataProcessor::init() {}
while (true) {
printk("app::SensorDataProcessor::entryPoint - Running...\n"); void app::SensorDataProcessor::run() {
k_sleep(K_SECONDS(5)); printk("app::SensorDataProcessor::run - Running...\n");
} k_sleep(K_SECONDS(5));
} }
void app::SensorDataProcessor::finalize() {}
+8 -3
View File
@@ -1,15 +1,20 @@
#ifndef SENSOR_DATA_PROCESSOR_HPP #ifndef SENSOR_DATA_PROCESSOR_HPP
#define SENSOR_DATA_PROCESSOR_HPP #define SENSOR_DATA_PROCESSOR_HPP
#include "ThreadWrapper.hpp"
namespace app { namespace app {
class SensorDataProcessor { class SensorDataProcessor : public ThreadWrapper<SensorDataProcessor> {
public: public:
SensorDataProcessor() = default; SensorDataProcessor() = default;
~SensorDataProcessor() = default; ~SensorDataProcessor() = default;
// Thread entry void init();
static void entryPoint(void *, void *, void *);
void run();
void finalize();
private: private:
}; };
+7 -5
View File
@@ -1,9 +1,11 @@
#include "SensorSampler.hpp" #include "SensorSampler.hpp"
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
void app::SensorSampler::entryPoint(void *, void *, void *) { void app::SensorSampler::init() {}
while (true) {
printk("app::SensorSampler::entryPoint - Running...\n"); void app::SensorSampler::run() {
k_sleep(K_SECONDS(5)); printk("app::SensorSampler::run - Running...\n");
} k_sleep(K_SECONDS(5));
} }
void app::SensorSampler::finalize() {}
+8 -3
View File
@@ -1,15 +1,20 @@
#ifndef SENSOR_SAMPLER_HPP #ifndef SENSOR_SAMPLER_HPP
#define SENSOR_SAMPLER_HPP #define SENSOR_SAMPLER_HPP
#include "ThreadWrapper.hpp"
namespace app { namespace app {
class SensorSampler { class SensorSampler : public ThreadWrapper<SensorSampler> {
public: public:
SensorSampler() = default; SensorSampler() = default;
~SensorSampler() = default; ~SensorSampler() = default;
// Thread entry void init();
static void entryPoint(void *, void *, void *);
void run();
void finalize();
private: private:
}; };
+36
View File
@@ -0,0 +1,36 @@
#ifndef THREAD_WRAPPER_HPP
#define THREAD_WRAPPER_HPP
#include <cstddef>
namespace app {
template <typename ThreadType> class ThreadWrapper {
public:
/**
* @brief Entry point to thread. Must define init(), run(), and finalize() for
* thread type.
*
*/
inline static void entryPoint(void *, void *, void *) {
auto thread = ThreadType();
thread.init();
while (true) {
thread.run();
thread.incrementRunCount();
}
// NOTE: Maybe one day I'll add logic to be able to finalize a thread...
thread.finalize();
}
private:
inline void incrementRunCount() { ++runCounter_; }
std::size_t runCounter_ = 0;
};
} // namespace app
#endif