Skip to content

Commit d0f24b7

Browse files
committed
Multi-threaded parsing: added locks around global data
1 parent 46672f1 commit d0f24b7

File tree

9 files changed

+95
-68
lines changed

9 files changed

+95
-68
lines changed

src/commentscan.l

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <map>
3131
#include <stack>
3232
#include <string>
33+
#include <mutex>
3334

3435
#include <stdio.h>
3536
#include <stdlib.h>
@@ -401,6 +402,13 @@ struct commentscanYY_state
401402
bool markdownSupport = TRUE;
402403
};
403404

405+
406+
#if MULTITHREADED_INPUT
407+
static std::mutex g_sectionMutex;
408+
static std::mutex g_formulaMutex;
409+
static std::mutex g_citeMutex;
410+
#endif
411+
404412
//-----------------------------------------------------------------------------
405413

406414
static QCString stripQuotes(const char *s);
@@ -2786,6 +2794,10 @@ static void addXRefItem(yyscan_t yyscanner,
27862794
if (listName==0) return;
27872795
//printf("addXRefItem(%s,%s,%s,%d)\n",listName,itemTitle,listTitle,append);
27882796

2797+
#if MULTITHREADED_INPUT
2798+
std::unique_lock<std::mutex> lock(g_sectionMutex);
2799+
#endif
2800+
27892801
RefList *refList = RefListManager::instance().add(listName,listTitle,itemTitle);
27902802
RefItem *item = 0;
27912803
for (RefItem *i : yyextra->current->sli)
@@ -2826,26 +2838,28 @@ static void addXRefItem(yyscan_t yyscanner,
28262838
yyextra->current->doc += cmdString;
28272839
}
28282840

2829-
SectionManager &sm = SectionManager::instance();
2830-
const SectionInfo *si = sm.find(anchorLabel);
2831-
if (si)
28322841
{
2833-
if (si->lineNr() != -1)
2842+
SectionManager &sm = SectionManager::instance();
2843+
const SectionInfo *si = sm.find(anchorLabel);
2844+
if (si)
28342845
{
2835-
warn(listName,yyextra->lineNr,"multiple use of section label '%s', (first occurrence: %s, line %d)",anchorLabel.data(),si->fileName().data(),si->lineNr());
2846+
if (si->lineNr() != -1)
2847+
{
2848+
warn(listName,yyextra->lineNr,"multiple use of section label '%s', (first occurrence: %s, line %d)",anchorLabel.data(),si->fileName().data(),si->lineNr());
2849+
}
2850+
else
2851+
{
2852+
warn(listName,yyextra->lineNr,"multiple use of section label '%s', (first occurrence: %s)",anchorLabel.data(),si->fileName().data());
2853+
}
28362854
}
28372855
else
28382856
{
2839-
warn(listName,yyextra->lineNr,"multiple use of section label '%s', (first occurrence: %s)",anchorLabel.data(),si->fileName().data());
2857+
si = sm.add(anchorLabel,listName,yyextra->lineNr,
2858+
yyextra->sectionTitle,SectionType::Anchor,
2859+
yyextra->sectionLevel);
2860+
yyextra->current->anchors.push_back(si);
28402861
}
28412862
}
2842-
else
2843-
{
2844-
si = sm.add(anchorLabel,listName,yyextra->lineNr,
2845-
yyextra->sectionTitle,SectionType::Anchor,
2846-
yyextra->sectionLevel);
2847-
yyextra->current->anchors.push_back(si);
2848-
}
28492863
}
28502864
yyextra->outputXRef.resize(0);
28512865
}
@@ -2856,6 +2870,9 @@ static void addXRefItem(yyscan_t yyscanner,
28562870
// not already added. Returns the label of the formula.
28572871
static QCString addFormula(yyscan_t yyscanner)
28582872
{
2873+
#if MULTITHREADED_INPUT
2874+
std::unique_lock<std::mutex> lock(g_formulaMutex);
2875+
#endif
28592876
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
28602877
QCString formLabel;
28612878
QCString fText=yyextra->formulaText.simplifyWhiteSpace();
@@ -2877,6 +2894,9 @@ static SectionType sectionLevelToType(int level)
28772894

28782895
static void addSection(yyscan_t yyscanner)
28792896
{
2897+
#if MULTITHREADED_INPUT
2898+
std::unique_lock<std::mutex> lock(g_sectionMutex);
2899+
#endif
28802900
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
28812901
SectionManager &sm = SectionManager::instance();
28822902
const SectionInfo *si = sm.find(yyextra->sectionLabel);
@@ -2909,6 +2929,9 @@ static void addSection(yyscan_t yyscanner)
29092929

29102930
static void addCite(yyscan_t yyscanner)
29112931
{
2932+
#if MULTITHREADED_INPUT
2933+
std::unique_lock<std::mutex> lock(g_citeMutex);
2934+
#endif
29122935
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
29132936
QCString name=yytext;
29142937
if (yytext[0] =='"')
@@ -3060,6 +3083,9 @@ static inline void setOutput(yyscan_t yyscanner,OutputContext ctx)
30603083

30613084
static void addAnchor(yyscan_t yyscanner,const char *anchor)
30623085
{
3086+
#if MULTITHREADED_INPUT
3087+
std::unique_lock<std::mutex> lock(g_sectionMutex);
3088+
#endif
30633089
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
30643090
SectionManager &sm = SectionManager::instance();
30653091
const SectionInfo *si = sm.find(anchor);

src/doxygen.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ int Doxygen::subpageNestingLevel = 0;
158158
bool Doxygen::userComments = FALSE;
159159
QCString Doxygen::spaces;
160160
bool Doxygen::generatingXmlOutput = FALSE;
161-
//bool Doxygen::markdownSupport = TRUE;
162161
GenericsSDict *Doxygen::genericsDict;
163162
DefineList Doxygen::macroDefinitions;
164163

@@ -10299,8 +10298,6 @@ void adjustConfiguration()
1029910298
Config_getBool(REFERENCES_RELATION) ||
1030010299
Config_getBool(REFERENCED_BY_RELATION);
1030110300

10302-
//Doxygen::markdownSupport = Config_getBool(MARKDOWN_SUPPORT);
10303-
1030410301
/**************************************************************************
1030510302
* Add custom extension mappings
1030610303
**************************************************************************/

src/doxygen.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ class Doxygen
148148
static int subpageNestingLevel;
149149
static QCString spaces;
150150
static bool generatingXmlOutput;
151-
//static bool markdownSupport;
152151
static GenericsSDict *genericsDict;
153152
static DefineList macroDefinitions;
154153
};

src/entry.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424
#include "doxygen.h"
2525
#include "arguments.h"
2626
#include "config.h"
27-
//------------------------------------------------------------------
28-
29-
#define HEADER ('D'<<24)+('O'<<16)+('X'<<8)+'!'
3027

3128
//------------------------------------------------------------------
3229

33-
int Entry::num=0;
30+
static AtomicInt g_num;
3431

3532
Entry::Entry()
3633
{
3734
//printf("Entry::Entry(%p)\n",this);
38-
num++;
35+
g_num++;
3936
m_parent=0;
4037
section = EMPTY_SEC;
4138
//printf("Entry::Entry() tArgList=0\n");
@@ -50,7 +47,7 @@ Entry::Entry()
5047
Entry::Entry(const Entry &e)
5148
{
5249
//printf("Entry::Entry(%p):copy\n",this);
53-
num++;
50+
g_num++;
5451
section = e.section;
5552
type = e.type;
5653
name = e.name;
@@ -123,11 +120,11 @@ Entry::Entry(const Entry &e)
123120

124121
Entry::~Entry()
125122
{
126-
//printf("Entry::~Entry(%p) num=%d\n",this,num);
123+
//printf("Entry::~Entry(%p) num=%d\n",this,g_num);
127124
//printf("Deleting entry %d name %s type %x children %d\n",
128125
// num,name.data(),section,sublist->count());
129126

130-
num--;
127+
g_num--;
131128
}
132129

133130
void Entry::moveToSubEntryAndRefresh(Entry *&current)
@@ -183,10 +180,10 @@ void Entry::removeSubEntry(const Entry *e)
183180

184181
void Entry::reset()
185182
{
186-
static bool entryCallGraph = Config_getBool(CALL_GRAPH);
187-
static bool entryCallerGraph = Config_getBool(CALLER_GRAPH);
188-
static bool entryReferencedByRelation = Config_getBool(REFERENCED_BY_RELATION);
189-
static bool entryReferencesRelation = Config_getBool(REFERENCES_RELATION);
183+
bool entryCallGraph = Config_getBool(CALL_GRAPH);
184+
bool entryCallerGraph = Config_getBool(CALLER_GRAPH);
185+
bool entryReferencedByRelation = Config_getBool(REFERENCED_BY_RELATION);
186+
bool entryReferencesRelation = Config_getBool(REFERENCES_RELATION);
190187
//printf("Entry::reset()\n");
191188
name.resize(0);
192189
type.resize(0);

src/entry.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,6 @@ class Entry
297297
LocalToc localToc;
298298
QCString metaData; //!< Slice metadata
299299

300-
301-
static int num; //!< counts the total number of entries
302-
303300
/// return the command name used to define GROUPDOC_SEC
304301
const char *groupDocCmd() const
305302
{

src/markdown.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,11 +2574,6 @@ void MarkdownOutlineParser::parseInput(const char *fileName,
25742574
}
25752575
int lineNr=1;
25762576

2577-
// even without markdown support enabled, we still
2578-
// parse markdown files as such
2579-
//bool markdownEnabled = Doxygen::markdownSupport;
2580-
//Doxygen::markdownSupport = TRUE;
2581-
25822577
Protection prot=Public;
25832578
bool needsEntry = FALSE;
25842579
int position=0;
@@ -2610,9 +2605,6 @@ void MarkdownOutlineParser::parseInput(const char *fileName,
26102605
{
26112606
root->moveToSubEntryAndKeep(current);
26122607
}
2613-
2614-
// restore setting
2615-
//Doxygen::markdownSupport = markdownEnabled;
26162608
}
26172609

26182610
void MarkdownOutlineParser::parsePrototype(const char *text)

src/pagedef.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,6 @@ void PageDefImpl::writeDocumentation(OutputList &ol)
289289

290290
void PageDefImpl::writePageDocumentation(OutputList &ol)
291291
{
292-
293-
//bool markdownEnabled = Doxygen::markdownSupport;
294-
//if (getLanguage()==SrcLangExt_Markdown)
295-
//{
296-
// Doxygen::markdownSupport = TRUE;
297-
//}
298-
299292
ol.startTextBlock();
300293
QCString docStr = documentation()+inbodyDocumentation();
301294
if (hasBriefDescription() && !SectionManager::instance().find(name()))
@@ -320,8 +313,6 @@ void PageDefImpl::writePageDocumentation(OutputList &ol)
320313
);
321314
ol.endTextBlock();
322315

323-
//Doxygen::markdownSupport = markdownEnabled;
324-
325316
if (hasSubPages())
326317
{
327318
// for printed documentation we write subpages as section's of the

src/pre.l

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ void DefineManager::DefinesPerFile::collectDefines(
360360
*
361361
* global state
362362
*/
363+
#if MULTITHREADED_INPUT
364+
static std::mutex g_allIncludesMutex;
365+
static std::mutex g_addIncludeRelationMutex;
366+
static std::mutex g_macroDefinitionsMutex;
367+
#endif
363368
static StringUnorderedSet g_allIncludes;
364369
static DefineManager g_defineManager;
365370

@@ -1804,6 +1809,10 @@ static FileState *checkAndOpenFile(yyscan_t yyscanner,const QCString &fileName,b
18041809
// global guard
18051810
if (state->curlyCount==0) // not #include inside { ... }
18061811
{
1812+
#if MULTITHREADED_INPUT
1813+
std::unique_lock<std::mutex> lock(g_allIncludesMutex);
1814+
#endif
1815+
18071816
if (g_allIncludes.find(absName.data())!=g_allIncludes.end())
18081817
{
18091818
alreadyIncluded = TRUE;
@@ -2854,7 +2863,12 @@ static void addMacroDefinition(yyscan_t yyscanner)
28542863
{
28552864
define->definition = litTextStripped;
28562865
}
2857-
Doxygen::macroDefinitions.push_back(std::move(define));
2866+
{
2867+
#if MULTITHREADED_INPUT
2868+
std::unique_lock<std::mutex> lock(g_macroDefinitionsMutex);
2869+
#endif
2870+
Doxygen::macroDefinitions.push_back(std::move(define));
2871+
}
28582872
}
28592873

28602874
static inline void outputChar(yyscan_t yyscanner,char c)
@@ -2959,6 +2973,9 @@ static void readIncludeFile(yyscan_t yyscanner,const QCString &inc)
29592973
}
29602974
if (oldFileDef)
29612975
{
2976+
#if MULTITHREADED_INPUT
2977+
std::unique_lock<std::mutex> lock(g_addIncludeRelationMutex);
2978+
#endif
29622979
// add include dependency to the file in which the #include was found
29632980
bool ambig;
29642981
// change to absolute name for bug 641336
@@ -2973,6 +2990,9 @@ static void readIncludeFile(yyscan_t yyscanner,const QCString &inc)
29732990
}
29742991
else if (state->inputFileDef)
29752992
{
2993+
#if MULTITHREADED_INPUT
2994+
std::unique_lock<std::mutex> lock(g_addIncludeRelationMutex);
2995+
#endif
29762996
state->inputFileDef->addIncludeDependency(0,absIncFileName,localInclude,state->isImported,TRUE);
29772997
}
29782998
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -3002,6 +3022,9 @@ static void readIncludeFile(yyscan_t yyscanner,const QCString &inc)
30023022
//printf(" calling findFile(%s) alreadyInc=%d\n",incFileName.data(),alreadyIncluded);
30033023
if (oldFileDef)
30043024
{
3025+
#if MULTITHREADED_INPUT
3026+
std::unique_lock<std::mutex> lock(g_addIncludeRelationMutex);
3027+
#endif
30053028
bool ambig;
30063029

30073030
// change to absolute name for bug 641336
@@ -3018,6 +3041,9 @@ static void readIncludeFile(yyscan_t yyscanner,const QCString &inc)
30183041
}
30193042
else if (state->inputFileDef)
30203043
{
3044+
#if MULTITHREADED_INPUT
3045+
std::unique_lock<std::mutex> lock(g_addIncludeRelationMutex);
3046+
#endif
30213047
state->inputFileDef->addIncludeDependency(0,absIncFileName,localInclude,state->isImported,TRUE);
30223048
}
30233049
if (Debug::isFlagSet(Debug::Preprocessor))

0 commit comments

Comments
 (0)