diff --git a/runtime/Cpp/runtime/Parser.cpp b/runtime/Cpp/runtime/Parser.cpp index 76f587b9c..cc300b11c 100755 --- a/runtime/Cpp/runtime/Parser.cpp +++ b/runtime/Cpp/runtime/Parser.cpp @@ -238,7 +238,7 @@ const atn::ATN& Parser::getATNWithBypassAlts() { throw UnsupportedOperationException("The current parser does not support an ATN with bypass alternatives."); } - std::lock_guard lck(mtx); + std::lock_guard lck(mtx); // XXX: using the entire serialized ATN as key into the map is a big resource waste. // How large can that thing become? @@ -572,7 +572,7 @@ std::vector Parser::getRuleInvocationStack(Ref p) { std::vector Parser::getDFAStrings() { atn::ParserATNSimulator *simulator = getInterpreter(); if (!simulator->decisionToDFA.empty()) { - std::lock_guard lck(mtx); + std::lock_guard lck(mtx); std::vector s; for (size_t d = 0; d < simulator->decisionToDFA.size(); d++) { @@ -587,7 +587,7 @@ std::vector Parser::getDFAStrings() { void Parser::dumpDFA() { atn::ParserATNSimulator *simulator = getInterpreter(); if (!simulator->decisionToDFA.empty()) { - std::lock_guard lck(mtx); + std::lock_guard lck(mtx); bool seenOne = false; for (size_t d = 0; d < simulator->decisionToDFA.size(); d++) { dfa::DFA &dfa = simulator->decisionToDFA[d]; diff --git a/runtime/Cpp/runtime/Parser.h b/runtime/Cpp/runtime/Parser.h index 6124db1c0..557bfe35b 100755 --- a/runtime/Cpp/runtime/Parser.h +++ b/runtime/Cpp/runtime/Parser.h @@ -425,7 +425,7 @@ namespace runtime { std::vector _precedenceStack; //Mutex to manage synchronized access for multithreading in the parser - std::mutex mtx; + std::recursive_mutex mtx; /// /// Specifies whether or not the parser should construct a parse tree during diff --git a/runtime/Cpp/runtime/Recognizer.cpp b/runtime/Cpp/runtime/Recognizer.cpp index 36e9a8160..3c7a949a0 100755 --- a/runtime/Cpp/runtime/Recognizer.cpp +++ b/runtime/Cpp/runtime/Recognizer.cpp @@ -60,7 +60,7 @@ Ref Recognizer::getVocabulary() const { std::map Recognizer::getTokenTypeMap() { Ref vocabulary = getVocabulary(); - std::lock_guard lck(mtx); + std::lock_guard lck(mtx); std::map result; auto iterator = _tokenTypeMapCache.find(vocabulary); if (iterator != _tokenTypeMapCache.end()) { @@ -90,7 +90,7 @@ std::map Recognizer::getRuleIndexMap() { throw L"The current recognizer does not provide a list of rule names."; } - std::lock_guard lck(mtx); + std::lock_guard lck(mtx); std::map result; auto iterator = _ruleIndexMapCache.find(ruleNames); if (iterator != _ruleIndexMapCache.end()) { diff --git a/runtime/Cpp/runtime/Recognizer.h b/runtime/Cpp/runtime/Recognizer.h index 66e3b3277..e64960835 100755 --- a/runtime/Cpp/runtime/Recognizer.h +++ b/runtime/Cpp/runtime/Recognizer.h @@ -181,7 +181,7 @@ namespace runtime { ProxyErrorListener _proxListener; // Manages a collection of listeners. // Mutex to manage synchronized access for multithreading. - std::mutex mtx; + std::recursive_mutex mtx; int _stateNumber; diff --git a/runtime/Cpp/runtime/atn/ATNSimulator.cpp b/runtime/Cpp/runtime/atn/ATNSimulator.cpp index a7c5e5a70..d75291389 100755 --- a/runtime/Cpp/runtime/atn/ATNSimulator.cpp +++ b/runtime/Cpp/runtime/atn/ATNSimulator.cpp @@ -56,7 +56,7 @@ Ref ATNSimulator::getSharedContextCache() { } Ref ATNSimulator::getCachedContext(Ref context) { - std::lock_guard lck(mtx); + std::lock_guard lck(mtx); std::map, Ref> visited; return PredictionContext::getCachedContext(context, _sharedContextCache, visited); } diff --git a/runtime/Cpp/runtime/atn/ATNSimulator.h b/runtime/Cpp/runtime/atn/ATNSimulator.h index feadd57de..f775506d2 100755 --- a/runtime/Cpp/runtime/atn/ATNSimulator.h +++ b/runtime/Cpp/runtime/atn/ATNSimulator.h @@ -85,7 +85,7 @@ namespace atn { protected: // Mutex to manage synchronized access for multithreading - std::mutex mtx; + std::recursive_mutex mtx; /// /// The context cache maps all PredictionContext objects that are equals() diff --git a/runtime/Cpp/runtime/atn/LexerATNSimulator.cpp b/runtime/Cpp/runtime/atn/LexerATNSimulator.cpp index b169df0b7..ea5c5283e 100755 --- a/runtime/Cpp/runtime/atn/LexerATNSimulator.cpp +++ b/runtime/Cpp/runtime/atn/LexerATNSimulator.cpp @@ -563,7 +563,7 @@ void LexerATNSimulator::addDFAEdge(dfa::DFAState *p, ssize_t t, dfa::DFAState *q std::wcout << std::wstring(L"EDGE ") << p << std::wstring(L" -> ") << q << std::wstring(L" upon ") << (static_cast(t)) << std::endl; } - std::lock_guard lck(mtx); + std::lock_guard lck(mtx); if (p->edges.empty()) { // make room for tokens 1..n and -1 masquerading as index 0 p->edges.resize(MAX_DFA_EDGE - MIN_DFA_EDGE + 1); @@ -595,7 +595,7 @@ dfa::DFAState *LexerATNSimulator::addDFAState(Ref configs) { dfa::DFA &dfa = _decisionToDFA[_mode]; { - std::lock_guard lck(mtx); + std::lock_guard lck(mtx); auto iterator = dfa.states.find(proposed); if (iterator != dfa.states.end()) { diff --git a/runtime/Cpp/runtime/atn/ParserATNSimulator.cpp b/runtime/Cpp/runtime/atn/ParserATNSimulator.cpp index 0c7cbb02f..c95847db5 100755 --- a/runtime/Cpp/runtime/atn/ParserATNSimulator.cpp +++ b/runtime/Cpp/runtime/atn/ParserATNSimulator.cpp @@ -1205,7 +1205,7 @@ dfa::DFAState *ParserATNSimulator::addDFAEdge(dfa::DFA &dfa, dfa::DFAState *from } { - std::lock_guard lck(mtx); + std::lock_guard lck(mtx); if (from->edges.empty()) from->edges.resize(atn.maxTokenType + 1 + 1); from->edges[(size_t)(t + 1)] = to; // connect @@ -1228,7 +1228,7 @@ dfa::DFAState *ParserATNSimulator::addDFAState(dfa::DFA &dfa, dfa::DFAState *D) } { - std::lock_guard lck(mtx); + std::lock_guard lck(mtx); auto existing = dfa.states.find(D); if (existing != dfa.states.end()) { diff --git a/runtime/Cpp/runtime/atn/ParserATNSimulator.h b/runtime/Cpp/runtime/atn/ParserATNSimulator.h index 73a948304..5f044306c 100755 --- a/runtime/Cpp/runtime/atn/ParserATNSimulator.h +++ b/runtime/Cpp/runtime/atn/ParserATNSimulator.h @@ -290,7 +290,7 @@ namespace atn { PredictionMode mode; // Mutex to manage synchronized access for multithreading in the parser atn simulator. - std::mutex _lock; + std::recursive_mutex _lock; /// /// Each prediction operation uses a cache for merge of prediction contexts. diff --git a/runtime/Cpp/runtime/dfa/DFA.cpp b/runtime/Cpp/runtime/dfa/DFA.cpp index 11cd24fe8..387be2956 100755 --- a/runtime/Cpp/runtime/dfa/DFA.cpp +++ b/runtime/Cpp/runtime/dfa/DFA.cpp @@ -106,7 +106,7 @@ void DFA::setPrecedenceStartState(int precedence, DFAState *startState) { // synchronization on s0 here is ok. when the DFA is turned into a // precedence DFA, s0 will be initialized once and not updated again - std::unique_lock lock(_lock); + std::unique_lock lock(_lock); { // s0.edges is never null for a precedence DFA if (precedence >= (int)s0->edges.size()) { diff --git a/runtime/Cpp/runtime/dfa/DFA.h b/runtime/Cpp/runtime/dfa/DFA.h index 6ee7d777b..29cadede7 100755 --- a/runtime/Cpp/runtime/dfa/DFA.h +++ b/runtime/Cpp/runtime/dfa/DFA.h @@ -109,7 +109,7 @@ namespace dfa { */ bool _precedenceDfa; - std::mutex _lock; // To synchronize access to s0. + std::recursive_mutex _lock; // To synchronize access to s0. }; } // namespace atn diff --git a/runtime/Cpp/runtime/dfa/LexerDFASerializer.cpp b/runtime/Cpp/runtime/dfa/LexerDFASerializer.cpp index 48a0f3e28..e68dcf36b 100755 --- a/runtime/Cpp/runtime/dfa/LexerDFASerializer.cpp +++ b/runtime/Cpp/runtime/dfa/LexerDFASerializer.cpp @@ -29,11 +29,13 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "VocabularyImpl.h" + #include "LexerDFASerializer.h" using namespace org::antlr::v4::runtime::dfa; -LexerDFASerializer::LexerDFASerializer(DFA *dfa) : DFASerializer(dfa, lexerTokenNames_) { +LexerDFASerializer::LexerDFASerializer(DFA *dfa) : DFASerializer(dfa, VocabularyImpl::EMPTY_VOCABULARY) { } std::wstring LexerDFASerializer::getEdgeLabel(size_t i) const { diff --git a/runtime/Cpp/runtime/dfa/LexerDFASerializer.h b/runtime/Cpp/runtime/dfa/LexerDFASerializer.h index b975c126a..bb392cdb9 100755 --- a/runtime/Cpp/runtime/dfa/LexerDFASerializer.h +++ b/runtime/Cpp/runtime/dfa/LexerDFASerializer.h @@ -44,7 +44,6 @@ namespace dfa { LexerDFASerializer(DFA *dfa); protected: - std::vector lexerTokenNames_; virtual std::wstring getEdgeLabel(size_t i) const override; };