Skip to content

Commit

Permalink
Fixed another potential race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
gunterkoenigsmann committed Nov 27, 2022
1 parent 13cc85b commit 248bc1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
30 changes: 19 additions & 11 deletions src/MaximaManual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ void MaximaManual::AnchorAliasses(HelpFileAnchors &anchors) {
}
}

void MaximaManual::CompileHelpFileAnchors() {
void MaximaManual::CompileHelpFileAnchors(wxString maximaHtmlDir,
wxString maximaVersion,
wxString saveName) {
SuppressErrorDialogs suppressor;

int foundAnchorsTotal = 0;
Expand Down Expand Up @@ -267,7 +269,7 @@ void MaximaManual::CompileHelpFileAnchors() {
foundAnchors, foundAnchorsTotal));
}
if (foundAnchorsTotal > 100)
SaveManualAnchorsToCache();
SaveManualAnchorsToCache(maximaHtmlDir, maximaVersion, saveName);
else
LoadBuiltInManualAnchors();
}
Expand Down Expand Up @@ -306,7 +308,9 @@ MaximaManual::GetHTMLFiles_Recursive::OnDir(const wxString &WXUNUSED(dirname)) {
return wxDIR_CONTINUE;
}

void MaximaManual::SaveManualAnchorsToCache() {
void MaximaManual::SaveManualAnchorsToCache(wxString maximaHtmlDir,
wxString maximaVersion,
wxString saveName) {
long num = m_helpFileURLs_singlePage.size();
if (num <= 50) {
wxLogMessage(wxString::Format(_("Found only %li keywords in maxima's "
Expand All @@ -315,16 +319,16 @@ void MaximaManual::SaveManualAnchorsToCache() {
return;
}
wxXmlAttribute *htmlDir =
new wxXmlAttribute(wxT("html_dir"), m_maximaHtmlDir);
new wxXmlAttribute(wxT("html_dir"), maximaHtmlDir);

wxXmlAttribute *maximaVersion =
new wxXmlAttribute(wxT("maxima_version"), m_maximaVersion, htmlDir);
wxXmlAttribute *maximaVersionNode =
new wxXmlAttribute(wxT("maxima_version"), maximaVersion, htmlDir);

wxXmlNode *topNode =
new wxXmlNode(NULL, wxXML_DOCUMENT_NODE, wxEmptyString, wxEmptyString);
wxXmlNode *headNode =
new wxXmlNode(topNode, wxXML_ELEMENT_NODE, wxT("maxima_toc"),
wxEmptyString, maximaVersion);
wxEmptyString, maximaVersionNode);

MaximaManual::HelpFileAnchors::const_iterator it;
for (it = m_helpFileAnchors.begin(); it != m_helpFileAnchors.end(); ++it) {
Expand Down Expand Up @@ -365,8 +369,6 @@ void MaximaManual::SaveManualAnchorsToCache() {
"overwritten if maxima's version changes or the file cannot be read"));

xmlDoc.AppendToProlog(commentNode);

wxString saveName = Dirstructure::AnchorsCacheFile();
wxLogMessage(wxString::Format(_("Trying to cache the list of subjects the "
"manual contains in the file %s."),
saveName.utf8_str()));
Expand Down Expand Up @@ -519,8 +521,14 @@ void MaximaManual::LoadHelpFileAnchors(wxString docdir,
WaitForBackgroundProcess();
}
m_helpFileAnchorsThreadActive.lock();
m_helpfileanchorsThread = std::unique_ptr<std::thread>(
new std::thread(&MaximaManual::CompileHelpFileAnchors, this));
m_helpfileanchorsThread =
std::unique_ptr<std::thread>(
new std::thread(&MaximaManual::CompileHelpFileAnchors,
this,
m_maximaHtmlDir,
m_maximaVersion,
Dirstructure::AnchorsCacheFile()
));
} else {
wxLogMessage(_("Maxima help file not found!"));
LoadBuiltInManualAnchors();
Expand Down
8 changes: 6 additions & 2 deletions src/MaximaManual.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,19 @@ class MaximaManual
//! Search maxima's help file for command and variable names
void LoadHelpFileAnchors(wxString directory, wxString maximaVersion);
//! Collect all keyword anchors in the help file
void CompileHelpFileAnchors();
void CompileHelpFileAnchors(wxString maximaHtmlDir,
wxString maximaVersion,
wxString saveName);
//! Load the result from the last CompileHelpFileAnchors from the disk cache
bool LoadManualAnchorsFromCache();
//! Load the help file anchors from an wxXmlDocument
bool LoadManualAnchorsFromXML(wxXmlDocument xmlDocument, bool checkManualVersion = true);
//! Load the help file anchors from the built-in list
bool LoadBuiltInManualAnchors();
//! Save the list of help file anchors to the cache.
void SaveManualAnchorsToCache();
void SaveManualAnchorsToCache(wxString maximaHtmlDir,
wxString maximaVersion,
wxString saveName);
void WaitForBackgroundProcess();

~MaximaManual();
Expand Down

0 comments on commit 248bc1a

Please sign in to comment.