- Create `Include/` folder for all main projects - Fix some issues here and there (found while moving things) - All includes are now in `Tactility/` subfolder and must be included with that prefix. This fixes issues with clashing POSIX headers (e.g. `<semaphore.h>` versus Tactility's `Semaphore.h`)
46 lines
1.0 KiB
C++
46 lines
1.0 KiB
C++
#include "Tactility/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();
|
|
}
|
|
|
|
} |