Tactility/TactilityCore/Source/DispatcherThread.cpp
Ken Van Hoeylandt 9581978fc7
Re-implement Core2 and other improvements (#141)
- Create real drivers instead of wrapping M5Unified/M5GFX
- Display HAL improvements (better default base class behaviour)
- Fixed bug with LVGL statusbar service locking (would hang indefinitely waiting for mutex, causing WDT issues)
- Fixes for `Critical.h`
- Fixes and improvements for `Dispatcher` and `DispatcherThread`
2024-12-30 14:17:47 +01:00

46 lines
1002 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::StateStopped) {
stop();
}
}
void DispatcherThread::_threadMain() {
do {
dispatcher.consume(1000 / portTICK_PERIOD_MS);
} while (!interruptThread);
}
void DispatcherThread::dispatch(Callback callback, std::shared_ptr<void> context) {
dispatcher.dispatch(callback, std::move(context));
}
void DispatcherThread::start() {
interruptThread = false;
thread->start();
}
void DispatcherThread::stop() {
interruptThread = true;
thread->join();
}
}