Prevent signal and wait from racing

This commit is contained in:
Jason A. Donenfeld 2018-09-24 03:08:18 +02:00
parent 75a86c7cce
commit fcd5923cbc
1 changed files with 3 additions and 1 deletions

View File

@ -181,7 +181,7 @@ class WireGuardContext {
private var packetFlow: NEPacketTunnelFlow private var packetFlow: NEPacketTunnelFlow
private var outboundPackets: [NEPacket] = [] private var outboundPackets: [NEPacket] = []
private var isTunnelClosed: Bool = false private var isTunnelClosed: Bool = false
private let readPacketCondition = NSCondition() private var readPacketCondition = NSCondition()
init(packetFlow: NEPacketTunnelFlow) { init(packetFlow: NEPacketTunnelFlow) {
self.packetFlow = packetFlow self.packetFlow = packetFlow
@ -193,7 +193,9 @@ class WireGuardContext {
} }
func packetsRead(packets: [NEPacket]) { func packetsRead(packets: [NEPacket]) {
readPacketCondition.lock()
outboundPackets.append(contentsOf: packets) outboundPackets.append(contentsOf: packets)
readPacketCondition.unlock()
readPacketCondition.signal() readPacketCondition.signal()
} }