Tactility/TactilityCore/Source/DispatcherThread.cpp
Ken Van Hoeylandt 43c78c69d8
Thread, Timer and flash.sh improvements (#165)
- Various improvements to Thread and Timer:
  - Remove "mark as static" option as it is unused
  - Implemented core pinning for ESP32 platforms
  - Use `TickType_t` consistently (instead of `uint32_t`)
  - Use `enum class` instead of `enum`
- Fix for `flash.sh` not working when using `pip` to install `esptool`
2025-01-13 20:20:43 +01:00

46 lines
1016 B
C++

#include "DispatcherThread.h"
namespace tt {
int32_t dispatcherThreadMain(void* context) {
auto* dispatcherThread = (DispatcherThread*)context;
dispatcherThread->_threadMain();
return 0;
}
DispatcherThread::DispatcherThread(const std::string& threadName, size_t threadStackSize) {
thread = std::make_unique<Thread>(
threadName,
threadStackSize,
dispatcherThreadMain,
this
);
}
DispatcherThread::~DispatcherThread() {
if (thread->getState() != Thread::State::Stopped) {
stop();
}
}
void DispatcherThread::_threadMain() {
do {
dispatcher.consume(1000 / portTICK_PERIOD_MS);
} while (!interruptThread);
}
void DispatcherThread::dispatch(Dispatcher::Function function, std::shared_ptr<void> context) {
dispatcher.dispatch(function, std::move(context));
}
void DispatcherThread::start() {
interruptThread = false;
thread->start();
}
void DispatcherThread::stop() {
interruptThread = true;
thread->join();
}
}