Marking Mutex.synchronized with rethrow.

This commit is contained in:
Hanzhou Shi 2017-05-20 23:37:59 -07:00
parent 53b83d7184
commit 4c0bbfd768
6 changed files with 11 additions and 11 deletions

View File

@ -440,12 +440,12 @@ open class Parser: Recognizer<ParserATNSimulator> {
let serializedAtn: String = getSerializedATN()
var result: ATN? = bypassAltsAtnCache[serializedAtn]
try! bypassAltsAtnCacheMutex.synchronized {
bypassAltsAtnCacheMutex.synchronized {
[unowned self] in
if result == nil {
let deserializationOptions: ATNDeserializationOptions = ATNDeserializationOptions()
try! deserializationOptions.setGenerateRuleBypassTransitions(true)
result = try! ATNDeserializer(deserializationOptions).deserialize(Array(serializedAtn.characters))
result = try! ATNDeserializer(deserializationOptions).deserialize(Array(serializedAtn.characters))
self.bypassAltsAtnCache[serializedAtn] = result!
}
}
@ -986,7 +986,7 @@ open class Parser: Recognizer<ParserATNSimulator> {
guard let _interp = _interp else {
return s
}
try! decisionToDFAMutex.synchronized {
decisionToDFAMutex.synchronized {
[unowned self] in
for d in 0..<_interp.decisionToDFA.count {
@ -1003,7 +1003,7 @@ open class Parser: Recognizer<ParserATNSimulator> {
guard let _interp = _interp else {
return
}
try! decisionToDFAMutex.synchronized {
decisionToDFAMutex.synchronized {
[unowned self] in
var seenOne: Bool = false

View File

@ -63,7 +63,7 @@ open class Recognizer<ATNInterpreter:ATNSimulator> {
public func getTokenTypeMap() -> Dictionary<String, Int> {
let vocabulary: Vocabulary = getVocabulary()
var result: Dictionary<String, Int>? = self.tokenTypeMapCache[vocabulary]
try! tokenTypeMapCacheMutex.synchronized {
tokenTypeMapCacheMutex.synchronized {
[unowned self] in
if result == nil {
result = Dictionary<String, Int>()
@ -100,7 +100,7 @@ open class Recognizer<ATNInterpreter:ATNSimulator> {
let ruleNames: [String] = getRuleNames()
let result: Dictionary<String, Int>? = self.ruleIndexMapCache[ArrayWrapper<String>(ruleNames)]
try! ruleIndexMapCacheMutex.synchronized {
ruleIndexMapCacheMutex.synchronized {
[unowned self] in
if result == nil {
self.ruleIndexMapCache[ArrayWrapper<String>(ruleNames)] = Utils.toMap(ruleNames)

View File

@ -655,7 +655,7 @@ open class LexerATNSimulator: ATNSimulator {
print("EDGE \(p) -> \(q) upon \(t)")
}
try! dfaStateMutex.synchronized {
dfaStateMutex.synchronized {
if p.edges == nil {
// make room for tokens 1..n and -1 masquerading as index 0
//TODO ARRAY COUNT
@ -686,7 +686,7 @@ open class LexerATNSimulator: ATNSimulator {
let dfa: DFA = decisionToDFA[mode]
return try! dfaStatesMutex.synchronized {
return dfaStatesMutex.synchronized {
if let existing = dfa.states[proposed] {
return existing!
}

View File

@ -1977,7 +1977,7 @@ open class ParserATNSimulator: ATNSimulator {
guard let from = from else {
return to
}
try! dfaStateMutex.synchronized {
dfaStateMutex.synchronized {
[unowned self] in
if from.edges == nil {
from.edges = [DFAState?](repeating: nil, count: self.atn.maxTokenType + 1 + 1) //new DFAState[atn.maxTokenType+1+1];

View File

@ -105,7 +105,7 @@ public class DFA: CustomStringConvertible {
}
// synchronization on s0 here is ok. when the DFA is turned into a
// 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
if precedence >= edges.count {
let increase = [DFAState?](repeating: nil, count: (precedence + 1 - edges.count))

View File

@ -19,7 +19,7 @@ class Mutex {
/// - Returns: the value returned by the closure
/// - Throws: the exception populated by the closure run
@discardableResult
func synchronized<R>(closure: () throws -> R) throws -> R {
func synchronized<R>(closure: () throws -> R) rethrows -> R {
pthread_mutex_lock(&mutex)
defer {
pthread_mutex_unlock(&mutex)