From a7d96765d69cf02228b8409be756d7112c9ecffd Mon Sep 17 00:00:00 2001 From: Krunoslav Zaher Date: Sun, 14 Feb 2016 12:23:19 -0800 Subject: [PATCH] Fixes compilation on Linux. --- RxBlocking/RunLoopLock.swift | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/RxBlocking/RunLoopLock.swift b/RxBlocking/RunLoopLock.swift index 2f32c630..3f44ff01 100644 --- a/RxBlocking/RunLoopLock.swift +++ b/RxBlocking/RunLoopLock.swift @@ -11,11 +11,28 @@ import Foundation import RxSwift #endif +typealias AtomicInt = Int32 + +#if os(Linux) + func AtomicIncrement(increment: UnsafeMutablePointer) -> AtomicInt { + increment.memory = increment.memory + 1 + return increment.memory + } + + func AtomicDecrement(increment: UnsafeMutablePointer) -> AtomicInt { + increment.memory = increment.memory - 1 + return increment.memory + } +#else + let AtomicIncrement = OSAtomicIncrement32 + let AtomicDecrement = OSAtomicDecrement32 +#endif + class RunLoopLock { let currentRunLoop: CFRunLoopRef - var calledRun: Int32 = 0 - var calledStop: Int32 = 0 + var calledRun: AtomicInt = 0 + var calledStop: AtomicInt = 0 init() { currentRunLoop = CFRunLoopGetCurrent() @@ -37,7 +54,7 @@ class RunLoopLock { } func stop() { - if OSAtomicIncrement32(&calledStop) != 1 { + if AtomicIncrement(&calledStop) != 1 { return } CFRunLoopPerformBlock(currentRunLoop, kCFRunLoopDefaultMode) { @@ -47,7 +64,7 @@ class RunLoopLock { } func run() { - if OSAtomicIncrement32(&calledRun) != 1 { + if AtomicIncrement(&calledRun) != 1 { fatalError("Run can be only called once") } CFRunLoopRun()