Fixes compilation on Linux.

This commit is contained in:
Krunoslav Zaher 2016-02-14 12:23:19 -08:00
parent db5959fc6e
commit a7d96765d6
1 changed files with 21 additions and 4 deletions

View File

@ -11,11 +11,28 @@ import Foundation
import RxSwift import RxSwift
#endif #endif
typealias AtomicInt = Int32
#if os(Linux)
func AtomicIncrement(increment: UnsafeMutablePointer<AtomicInt>) -> AtomicInt {
increment.memory = increment.memory + 1
return increment.memory
}
func AtomicDecrement(increment: UnsafeMutablePointer<AtomicInt>) -> AtomicInt {
increment.memory = increment.memory - 1
return increment.memory
}
#else
let AtomicIncrement = OSAtomicIncrement32
let AtomicDecrement = OSAtomicDecrement32
#endif
class RunLoopLock { class RunLoopLock {
let currentRunLoop: CFRunLoopRef let currentRunLoop: CFRunLoopRef
var calledRun: Int32 = 0 var calledRun: AtomicInt = 0
var calledStop: Int32 = 0 var calledStop: AtomicInt = 0
init() { init() {
currentRunLoop = CFRunLoopGetCurrent() currentRunLoop = CFRunLoopGetCurrent()
@ -37,7 +54,7 @@ class RunLoopLock {
} }
func stop() { func stop() {
if OSAtomicIncrement32(&calledStop) != 1 { if AtomicIncrement(&calledStop) != 1 {
return return
} }
CFRunLoopPerformBlock(currentRunLoop, kCFRunLoopDefaultMode) { CFRunLoopPerformBlock(currentRunLoop, kCFRunLoopDefaultMode) {
@ -47,7 +64,7 @@ class RunLoopLock {
} }
func run() { func run() {
if OSAtomicIncrement32(&calledRun) != 1 { if AtomicIncrement(&calledRun) != 1 {
fatalError("Run can be only called once") fatalError("Run can be only called once")
} }
CFRunLoopRun() CFRunLoopRun()