forked from jasder/antlr
Marking Mutex.synchronized with rethrow.
This commit is contained in:
parent
53b83d7184
commit
4c0bbfd768
|
@ -440,12 +440,12 @@ open class Parser: Recognizer<ParserATNSimulator> {
|
||||||
let serializedAtn: String = getSerializedATN()
|
let serializedAtn: String = getSerializedATN()
|
||||||
|
|
||||||
var result: ATN? = bypassAltsAtnCache[serializedAtn]
|
var result: ATN? = bypassAltsAtnCache[serializedAtn]
|
||||||
try! bypassAltsAtnCacheMutex.synchronized {
|
bypassAltsAtnCacheMutex.synchronized {
|
||||||
[unowned self] in
|
[unowned self] in
|
||||||
if result == nil {
|
if result == nil {
|
||||||
let deserializationOptions: ATNDeserializationOptions = ATNDeserializationOptions()
|
let deserializationOptions: ATNDeserializationOptions = ATNDeserializationOptions()
|
||||||
try! deserializationOptions.setGenerateRuleBypassTransitions(true)
|
try! deserializationOptions.setGenerateRuleBypassTransitions(true)
|
||||||
result = try! ATNDeserializer(deserializationOptions).deserialize(Array(serializedAtn.characters))
|
result = try! ATNDeserializer(deserializationOptions).deserialize(Array(serializedAtn.characters))
|
||||||
self.bypassAltsAtnCache[serializedAtn] = result!
|
self.bypassAltsAtnCache[serializedAtn] = result!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -986,7 +986,7 @@ open class Parser: Recognizer<ParserATNSimulator> {
|
||||||
guard let _interp = _interp else {
|
guard let _interp = _interp else {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
try! decisionToDFAMutex.synchronized {
|
decisionToDFAMutex.synchronized {
|
||||||
[unowned self] in
|
[unowned self] in
|
||||||
|
|
||||||
for d in 0..<_interp.decisionToDFA.count {
|
for d in 0..<_interp.decisionToDFA.count {
|
||||||
|
@ -1003,7 +1003,7 @@ open class Parser: Recognizer<ParserATNSimulator> {
|
||||||
guard let _interp = _interp else {
|
guard let _interp = _interp else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try! decisionToDFAMutex.synchronized {
|
decisionToDFAMutex.synchronized {
|
||||||
[unowned self] in
|
[unowned self] in
|
||||||
var seenOne: Bool = false
|
var seenOne: Bool = false
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ open class Recognizer<ATNInterpreter:ATNSimulator> {
|
||||||
public func getTokenTypeMap() -> Dictionary<String, Int> {
|
public func getTokenTypeMap() -> Dictionary<String, Int> {
|
||||||
let vocabulary: Vocabulary = getVocabulary()
|
let vocabulary: Vocabulary = getVocabulary()
|
||||||
var result: Dictionary<String, Int>? = self.tokenTypeMapCache[vocabulary]
|
var result: Dictionary<String, Int>? = self.tokenTypeMapCache[vocabulary]
|
||||||
try! tokenTypeMapCacheMutex.synchronized {
|
tokenTypeMapCacheMutex.synchronized {
|
||||||
[unowned self] in
|
[unowned self] in
|
||||||
if result == nil {
|
if result == nil {
|
||||||
result = Dictionary<String, Int>()
|
result = Dictionary<String, Int>()
|
||||||
|
@ -100,7 +100,7 @@ open class Recognizer<ATNInterpreter:ATNSimulator> {
|
||||||
let ruleNames: [String] = getRuleNames()
|
let ruleNames: [String] = getRuleNames()
|
||||||
|
|
||||||
let result: Dictionary<String, Int>? = self.ruleIndexMapCache[ArrayWrapper<String>(ruleNames)]
|
let result: Dictionary<String, Int>? = self.ruleIndexMapCache[ArrayWrapper<String>(ruleNames)]
|
||||||
try! ruleIndexMapCacheMutex.synchronized {
|
ruleIndexMapCacheMutex.synchronized {
|
||||||
[unowned self] in
|
[unowned self] in
|
||||||
if result == nil {
|
if result == nil {
|
||||||
self.ruleIndexMapCache[ArrayWrapper<String>(ruleNames)] = Utils.toMap(ruleNames)
|
self.ruleIndexMapCache[ArrayWrapper<String>(ruleNames)] = Utils.toMap(ruleNames)
|
||||||
|
|
|
@ -655,7 +655,7 @@ open class LexerATNSimulator: ATNSimulator {
|
||||||
print("EDGE \(p) -> \(q) upon \(t)")
|
print("EDGE \(p) -> \(q) upon \(t)")
|
||||||
}
|
}
|
||||||
|
|
||||||
try! dfaStateMutex.synchronized {
|
dfaStateMutex.synchronized {
|
||||||
if p.edges == nil {
|
if p.edges == nil {
|
||||||
// make room for tokens 1..n and -1 masquerading as index 0
|
// make room for tokens 1..n and -1 masquerading as index 0
|
||||||
//TODO ARRAY COUNT
|
//TODO ARRAY COUNT
|
||||||
|
@ -686,7 +686,7 @@ open class LexerATNSimulator: ATNSimulator {
|
||||||
|
|
||||||
let dfa: DFA = decisionToDFA[mode]
|
let dfa: DFA = decisionToDFA[mode]
|
||||||
|
|
||||||
return try! dfaStatesMutex.synchronized {
|
return dfaStatesMutex.synchronized {
|
||||||
if let existing = dfa.states[proposed] {
|
if let existing = dfa.states[proposed] {
|
||||||
return existing!
|
return existing!
|
||||||
}
|
}
|
||||||
|
|
|
@ -1977,7 +1977,7 @@ open class ParserATNSimulator: ATNSimulator {
|
||||||
guard let from = from else {
|
guard let from = from else {
|
||||||
return to
|
return to
|
||||||
}
|
}
|
||||||
try! dfaStateMutex.synchronized {
|
dfaStateMutex.synchronized {
|
||||||
[unowned self] in
|
[unowned self] in
|
||||||
if from.edges == nil {
|
if from.edges == nil {
|
||||||
from.edges = [DFAState?](repeating: nil, count: self.atn.maxTokenType + 1 + 1) //new DFAState[atn.maxTokenType+1+1];
|
from.edges = [DFAState?](repeating: nil, count: self.atn.maxTokenType + 1 + 1) //new DFAState[atn.maxTokenType+1+1];
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class DFA: CustomStringConvertible {
|
||||||
}
|
}
|
||||||
// synchronization on s0 here is ok. when the DFA is turned into a
|
// synchronization on s0 here is ok. when the DFA is turned into a
|
||||||
// precedence DFA, s0 will be initialized once and not updated again
|
// precedence DFA, s0 will be initialized once and not updated again
|
||||||
try! dfaStateMutex.synchronized {
|
dfaStateMutex.synchronized {
|
||||||
// s0.edges is never null for a precedence DFA
|
// s0.edges is never null for a precedence DFA
|
||||||
if precedence >= edges.count {
|
if precedence >= edges.count {
|
||||||
let increase = [DFAState?](repeating: nil, count: (precedence + 1 - edges.count))
|
let increase = [DFAState?](repeating: nil, count: (precedence + 1 - edges.count))
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Mutex {
|
||||||
/// - Returns: the value returned by the closure
|
/// - Returns: the value returned by the closure
|
||||||
/// - Throws: the exception populated by the closure run
|
/// - Throws: the exception populated by the closure run
|
||||||
@discardableResult
|
@discardableResult
|
||||||
func synchronized<R>(closure: () throws -> R) throws -> R {
|
func synchronized<R>(closure: () throws -> R) rethrows -> R {
|
||||||
pthread_mutex_lock(&mutex)
|
pthread_mutex_lock(&mutex)
|
||||||
defer {
|
defer {
|
||||||
pthread_mutex_unlock(&mutex)
|
pthread_mutex_unlock(&mutex)
|
||||||
|
|
Loading…
Reference in New Issue