Created
September 24, 2021 12:31
-
-
Save serhiybutz/2fd29ac4319c5f02e70af390b6a73fd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class Borrowing { | |
private let props: [AnyObject] | |
private let revokeCond = NSCondition() | |
private var isRevoked = false | |
init(_ props: [AnyObject]) { | |
self.props = props | |
} | |
func wait() { | |
revokeCond.lock() | |
defer { revokeCond.unlock() } | |
while !isRevoked { | |
revokeCond.wait() | |
} | |
} | |
func revoke() { | |
revokeCond.lock() | |
defer { revokeCond.unlock() } | |
if !isRevoked { | |
isRevoked = true | |
revokeCond.broadcast() | |
} | |
} | |
func hasConfictWith(_ another: Borrowing) -> Bool { | |
return props.contains { a in another.props.contains { b in a === b } } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment