Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public
- struct
- AtomicInteger : ExpressibleByIntegerLiteral
- {
- fileprivate let queue = DispatchQueue(label: "AtomicInteger Queue", qos: .userInteractive)
- fileprivate var internalValue: Int
- var value: Int
- {
- get
- {
- var result: Int = 0
- self.queue.sync
- {
- result = self.internalValue
- }
- return result
- }
- }
- public
- init(_ inValue: Int)
- {
- self.internalValue = inValue
- }
- public
- init(integerLiteral inValue: Int)
- {
- self.internalValue = inValue
- }
- }
- func
- +=(_ inLHS: inout AtomicInteger, _ inRHS: Int)
- {
- inLHS.queue.sync
- {
- inLHS.internalValue += inRHS
- }
- }
- func
- -=(_ inLHS: inout AtomicInteger, _ inRHS: Int)
- {
- inLHS.queue.sync
- {
- inLHS.internalValue -= inRHS
- }
- }
- extension
- Int
- {
- init(_ inValue: AtomicInteger)
- {
- self.init(inValue.value)
- }
- }
- var a = AtomicInteger(4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement