mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 19:03:16 +00:00
Improved the docs for the 3 main Tactility projects. I also fixed some inaccuracies and bugs in certain APIs as I went through the code.
46 lines
1014 B
C++
46 lines
1014 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(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();
|
|
}
|
|
|
|
} |