Skip to content

Commit f9c665a

Browse files
committed
for whatever reason I was able trigger a race condition because of the last commit
1 parent b67b6ab commit f9c665a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Source/SwiftRegex.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ import Foundation
1515

1616
infix operator <~ { associativity none precedence 130 }
1717

18+
private let lock = dispatch_semaphore_create(1)
1819
private var swiftRegexCache = [String: NSRegularExpression]()
1920

2021
internal final class SwiftRegex: NSObject, BooleanType {
2122
var target:String
2223
var regex: NSRegularExpression
2324

2425
init(target:String, pattern:String, options:NSRegularExpressionOptions?) {
26+
if dispatch_semaphore_wait(lock, dispatch_time(DISPATCH_TIME_NOW, Int64(10 * NSEC_PER_MSEC))) != 0 {
27+
fatalError("This should never happen")
28+
}
29+
2530
self.target = target
2631
if let regex = swiftRegexCache[pattern] {
2732
self.regex = regex
@@ -36,6 +41,7 @@ internal final class SwiftRegex: NSObject, BooleanType {
3641
self.regex = NSRegularExpression()
3742
}
3843
}
44+
dispatch_semaphore_signal(lock)
3945
super.init()
4046
}
4147

0 commit comments

Comments
 (0)