Skip to content

Commit

Permalink
Linux cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
kzaher committed Oct 9, 2016
1 parent c6b0cf4 commit fb75df5
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 213 deletions.
2 changes: 1 addition & 1 deletion RxBlocking/RunLoopLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ class RunLoopLock {
}
}
}
#endif
#endif
76 changes: 2 additions & 74 deletions RxSwift/Concurrency/Lock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,8 @@ protocol Lock {
func unlock()
}

#if os(Linux)
import Glibc

/**
Simple wrapper for spin lock.
*/
class SpinLock {
private var _lock: pthread_spinlock_t = 0

init() {
if (pthread_spin_init(&_lock, 0) != 0) {
fatalError("Spin lock initialization failed")
}
}

func lock() {
pthread_spin_lock(&_lock)
}

func unlock() {
pthread_spin_unlock(&_lock)
}

func performLocked(action: () -> Void) {
lock(); defer { unlock() }
action()
}

func calculateLocked<T>(action: () -> T) -> T {
lock(); defer { unlock() }
return action()
}

func calculateLockedOrFail<T>(action: () throws -> T) throws -> T {
lock(); defer { unlock() }
let result = try action()
return result
}

deinit {
pthread_spin_destroy(&_lock)
}
}
#else

// https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000321.html
typealias SpinLock = NSRecursiveLock
#endif
// https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000321.html
typealias SpinLock = NSRecursiveLock

extension NSRecursiveLock : Lock {
func performLocked(_ action: () -> Void) {
Expand All @@ -79,29 +33,3 @@ extension NSRecursiveLock : Lock {
return result
}
}

/*
let RECURSIVE_MUTEX = _initializeRecursiveMutex()
func _initializeRecursiveMutex() -> pthread_mutex_t {
var mutex: pthread_mutex_t = pthread_mutex_t()
var mta: pthread_mutexattr_t = pthread_mutexattr_t()
pthread_mutex_init(&mutex, nil)
pthread_mutexattr_init(&mta)
pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE)
pthread_mutex_init(&mutex, &mta)
return mutex
}
extension pthread_mutex_t {
mutating func lock() {
pthread_mutex_lock(&self)
}
mutating func unlock() {
pthread_mutex_unlock(&self)
}
}
*/
6 changes: 3 additions & 3 deletions RxSwift/Platform/Platform.Darwin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
typealias AtomicInt = Int32
#endif

public let AtomicCompareAndSwap = OSAtomicCompareAndSwap32
public let AtomicIncrement = OSAtomicIncrement32
public let AtomicDecrement = OSAtomicDecrement32
let AtomicCompareAndSwap = OSAtomicCompareAndSwap32
let AtomicIncrement = OSAtomicIncrement32
let AtomicDecrement = OSAtomicDecrement32

public extension Thread {
static func setThreadLocalStorageValue<T: AnyObject>(_ value: T?, forKey key: String
Expand Down
6 changes: 3 additions & 3 deletions RxSwift/Platform/Platform.Linux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@
typealias AtomicInt = Int64
#endif

public func AtomicIncrement(_ increment: UnsafeMutablePointer<AtomicInt>) -> AtomicInt {
func AtomicIncrement(_ increment: UnsafeMutablePointer<AtomicInt>) -> AtomicInt {
increment.pointee = increment.pointee + 1
return increment.pointee
}

public func AtomicDecrement(_ increment: UnsafeMutablePointer<AtomicInt>) -> AtomicInt {
func AtomicDecrement(_ increment: UnsafeMutablePointer<AtomicInt>) -> AtomicInt {
increment.pointee = increment.pointee - 1
return increment.pointee
}

public func AtomicCompareAndSwap(_ l: AtomicInt, _ r: AtomicInt, _ target: UnsafeMutablePointer<AtomicInt>) -> Bool {
func AtomicCompareAndSwap(_ l: AtomicInt, _ r: AtomicInt, _ target: UnsafeMutablePointer<AtomicInt>) -> Bool {
//return __sync_val_compare_and_swap(target, l, r)
if target.pointee == l {
target.pointee = r
Expand Down
2 changes: 0 additions & 2 deletions RxSwift/Schedulers/ConcurrentDispatchQueueScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
//

import Foundation
#if os(Linux)
import Dispatch
#endif

/**
Abstracts the work that needs to be performed on a specific `dispatch_queue_t`. You can also pass a serial dispatch queue, it shouldn't cause any problems.
Expand Down
2 changes: 0 additions & 2 deletions RxSwift/Schedulers/ConcurrentMainScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
//

import Foundation
#if os(Linux)
import Dispatch
#endif

/**
Abstracts work that needs to be performed on `MainThread`. In case `schedule` methods are called from main thread, it will perform action immediately without scheduling.
Expand Down
35 changes: 0 additions & 35 deletions RxSwift/Schedulers/CurrentThreadScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
//

import Foundation
#if os(Linux)
import Dispatch
#endif

#if os(Linux)
let CurrentThreadSchedulerKeyInstance = "RxSwift.CurrentThreadScheduler.SchedulerKey"
Expand All @@ -25,39 +23,6 @@ import Dispatch

typealias CurrentThreadSchedulerValue = NSString
let CurrentThreadSchedulerValueInstance = "RxSwift.CurrentThreadScheduler.SchedulerKey" as NSString

/*
let CurrentThreadSchedulerKeyInstance = CurrentThreadSchedulerKey()
let CurrentThreadSchedulerQueueKeyInstance = CurrentThreadSchedulerQueueKey()
typealias CurrentThreadSchedulerValue = CurrentThreadSchedulerKey
let CurrentThreadSchedulerValueInstance = CurrentThreadSchedulerKeyInstance
@objc class CurrentThreadSchedulerKey : NSObject, NSCopying {
override func isEqual(_ object: AnyObject?) -> Bool {
return object === CurrentThreadSchedulerKeyInstance
}
override var hash: Int { return -904739208 }
//func copy(with zone: NSZone? = nil) -> AnyObject {
func copyWithZone(zone: NSZone) -> AnyObject {
return CurrentThreadSchedulerKeyInstance
}
}
@objc class CurrentThreadSchedulerQueueKey : NSObject, NSCopying {
override func isEqual(_ object: AnyObject?) -> Bool {
return object === CurrentThreadSchedulerQueueKeyInstance
}
override var hash: Int { return -904739207 }
//func copy(with: NSZone?) -> AnyObject {
func copyWithZone(zone: NSZone) -> AnyObject {
return CurrentThreadSchedulerQueueKeyInstance
}
}*/
#endif

/**
Expand Down
2 changes: 0 additions & 2 deletions RxSwift/Schedulers/DispatchQueueSchedulerQOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
//

import Foundation
#if os(Linux)
import Dispatch
#endif

/**
Identifies one of the global concurrent dispatch queues with specified quality of service class.
Expand Down
2 changes: 0 additions & 2 deletions RxSwift/Schedulers/Internal/DispatchQueueConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
//

import Foundation
#if os(Linux)
import Dispatch
#endif

struct DispatchQueueConfiguration {
let queue: DispatchQueue
Expand Down
2 changes: 0 additions & 2 deletions RxSwift/Schedulers/MainScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
//

import Foundation
#if os(Linux)
import Dispatch
#endif

/**
Abstracts work that needs to be performed on `MainThread`. In case `schedule` methods are called from main thread, it will perform action immediately without scheduling.
Expand Down
2 changes: 0 additions & 2 deletions RxSwift/Schedulers/SerialDispatchQueueScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
//

import Foundation
#if os(Linux)
import Dispatch
#endif

/**
Abstracts the work that needs to be performed on a specific `dispatch_queue_t`. It will make sure
Expand Down
3 changes: 0 additions & 3 deletions Tests/RxSwiftTests/MainSchedulerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
//

import Foundation
#if os(Linux)
import Dispatch
#endif


import RxSwift
import XCTest
Expand Down
2 changes: 0 additions & 2 deletions Tests/RxSwiftTests/Observable+TimeTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,6 @@ extension ObservableTimeTest {
}

func testBufferWithTimeOrCount_Default() {
#if !os(Linux)
let backgroundScheduler = SerialDispatchQueueScheduler(globalConcurrentQueueQOS: .default)

let result = try! Observable.range(start: 1, count: 10, scheduler: backgroundScheduler)
Expand All @@ -1219,7 +1218,6 @@ extension ObservableTimeTest {
.first()

XCTAssertEqual(result!, [4, 5, 6])
#endif
}

}
Expand Down
2 changes: 0 additions & 2 deletions Tests/RxSwiftTests/SubjectConcurrencyTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import Foundation
@testable import RxSwift
import XCTest
#if os(Linux)
import Dispatch
#endif



Expand Down
2 changes: 0 additions & 2 deletions Tests/XCTest+AllTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import Foundation
import RxSwift
import RxTests
import XCTest
#if os(Linux)
import Dispatch
#endif

func XCTAssertErrorEqual(_ lhs: Swift.Error, _ rhs: Swift.Error) {
let event1: Event<Int> = .error(lhs)
Expand Down
43 changes: 0 additions & 43 deletions scripts/ast2test.py

This file was deleted.

Loading

0 comments on commit fb75df5

Please sign in to comment.