migrate fully to freeRTOS

This commit is contained in:
2025-02-15 22:21:19 +01:00
parent 4e94d7ad78
commit c13310d540
22 changed files with 226 additions and 410 deletions
+16 -26
View File
@@ -13,43 +13,39 @@
*/
#include "SPIT_Handler.h"
#include "esp_log.h"
mutex SPIT_Handler::s_MutexLock;
condition_variable SPIT_Handler::s_ConditionVariable;
fos::Mutex SPIT_Handler::s_MutexLock;
fos::Semaphore SPIT_Handler::s_ConditionVariable(1000);
list<SPIT_Handler::Runnable*> SPIT_Handler::s_Runnables;
bool SPIT_Handler::s_WakeUp = false;
bool SPIT_Handler::s_Close = false;
thread SPIT_Handler::s_HandlerThread(SPIT_Handler::run);
fos::Task* SPIT_Handler::s_HandlerThread = nullptr;
SPIT_Handler::Runnable::~Runnable() {}
void SPIT_Handler::addRunnable(Runnable* p_Runnable) {
if(s_HandlerThread == nullptr) {
s_HandlerThread = new fos::Task(SPIT_Handler::run, "spitHandler");
}
if (p_Runnable == NULL) return;
{
unique_lock<mutex> o_Unique_Lock(s_MutexLock);
fos::MutexGuard o_Unique_Lock(s_MutexLock);
if (s_Close == true) return;
s_Runnables.push_back(p_Runnable);
s_WakeUp = true;
}
if (this_thread::get_id() != s_HandlerThread.get_id()) {
s_ConditionVariable.notify_one();
}
s_ConditionVariable.give();
}
void SPIT_Handler::closeHandler() {
if (s_Close == true) return;
{
unique_lock<mutex> o_Unique_Lock(s_MutexLock);
fos::MutexGuard o_Unique_Lock(s_MutexLock);
if (s_Close == true) return;
s_Close = true;
s_WakeUp = true;
}
if (this_thread::get_id() != s_HandlerThread.get_id()) {
s_ConditionVariable.notify_one();
s_HandlerThread.join();
}
s_ConditionVariable.give();
}
void SPIT_Handler::run() {
Runnable* o_Runnable;
@@ -57,20 +53,16 @@ void SPIT_Handler::run() {
while (s_Close == false) {
boolWait = false;
{
unique_lock<mutex> o_Lock(s_MutexLock);
fos::MutexGuard o_Lock(s_MutexLock);
if (s_Runnables.empty()) {
s_ConditionVariable.wait(o_Lock, []{return s_WakeUp;});
s_ConditionVariable.take();
}
if (s_Close == true) {
s_WakeUp = true;
return;;
return;
}
s_WakeUp = false;
if (s_Runnables.empty()) {
o_Lock.unlock();
continue;
}
else {
@@ -85,9 +77,7 @@ void SPIT_Handler::run() {
delete o_Runnable;
}
catch(...) {
#if defined(DEBUGOUTPUT)
printf("ERROR SPITHandler o_Runable->run()\n");
#endif
ESP_LOGW("SPIT", "ERROR SPITHandler o_Runable->run()");
}
}
}