Skip to content

Commit

Permalink
Added protection against a race condition in the ESP32 config process…
Browse files Browse the repository at this point in the history
…ing loop.
  • Loading branch information
MartinMueller2003 committed Aug 22, 2023
1 parent dccf16b commit db9e878
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
30 changes: 20 additions & 10 deletions ESPixelStick/src/output/OutputMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ void c_OutputMgr::Begin ()

// CreateNewConfig ();

// load up the configuration from the saved file. This also starts the drivers
// DEBUG_V();
// DEBUG_V("load up the configuration from the saved file. This also starts the drivers");
LoadConfig();

// CreateNewConfig ();
Expand Down Expand Up @@ -1003,6 +1002,9 @@ void c_OutputMgr::LoadConfig ()
{
// DEBUG_START;

ConfigLoadNeeded = false;
ConfigInProgress = true;

// try to load and process the config file
if (!FileMgr.LoadConfigFile(ConfigFileName, [this](DynamicJsonDocument &JsonConfigDoc)
{
Expand Down Expand Up @@ -1032,6 +1034,8 @@ void c_OutputMgr::LoadConfig ()
}
}

ConfigInProgress = false;

// DEBUG_END;

} // LoadConfig
Expand Down Expand Up @@ -1290,11 +1294,10 @@ void c_OutputMgr::Poll()
// do we need to save the current config?
if (true == ConfigLoadNeeded)
{
ConfigLoadNeeded = false;
LoadConfig ();
} // done need to save the current config

if (false == IsOutputPaused)
if ((false == IsOutputPaused) && (false == ConfigInProgress))
{
// //DEBUG_V();
for (DriverInfo_t & OutputChannel : OutputChannelDrivers)
Expand All @@ -1318,23 +1321,30 @@ void c_OutputMgr::TaskPoll()
// do we need to save the current config?
if (true == ConfigLoadNeeded)
{
ConfigLoadNeeded = false;
// DEBUG_V("Starting config processing");
LoadConfig ();
// DEBUG_V("Done config processing");
} // done need to save the current config

if (false == IsOutputPaused)
if ((false == IsOutputPaused) && (false == ConfigInProgress))
{
// PollCount ++;
bool FoundAnActiveOutputChannel = false;
// //DEBUG_V();
for (DriverInfo_t & OutputChannel : OutputChannelDrivers)
{
// //DEBUG_V("Start a new channel");
uint32_t DelayInUs = OutputChannel.pOutputChannelDriver->Poll ();

if(DelayInUs)
if(nullptr != OutputChannel.pOutputChannelDriver)
{
uint32_t DelayInUs = OutputChannel.pOutputChannelDriver->Poll ();
if(DelayInUs)
{
FoundAnActiveOutputChannel = true;
}
}
else
{
FoundAnActiveOutputChannel = true;
// DEBUG_V(String("Missing pOutputChannelDriver for channel: ") + String(OutputChannel.DriverId));
}
}

Expand Down
1 change: 1 addition & 0 deletions ESPixelStick/src/output/OutputMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class c_OutputMgr

bool HasBeenInitialized = false;
bool ConfigLoadNeeded = false;
bool ConfigInProgress = false;
bool IsOutputPaused = false;
bool BuildingNewConfig = false;

Expand Down

0 comments on commit db9e878

Please sign in to comment.