Permalink
Browse files

Fix deprecated atomic APIs.

  • Loading branch information...
kzaher committed Oct 28, 2018
1 parent ba4d74c commit 761001436d607b351e7f6326a190b74f16202ea6
Showing with 714 additions and 199 deletions.
  1. +7 −6 .jazzy.yml
  2. +1 −0 .travis.yml
  3. +4 −2 Package.swift
  4. +33 −0 Platform/AtomicInt.swift
  5. +2 −32 Platform/Platform.Darwin.swift
  6. +0 −68 Platform/Platform.Linux.swift
  7. +180 −0 Rx.xcodeproj/project.pbxproj
  8. +21 −0 RxAtomic.podspec
  9. +22 −0 RxAtomic/Info.plist
  10. +7 −0 RxAtomic/RxAtomic.c
  11. +48 −0 RxAtomic/include/RxAtomic.h
  12. +1 −0 RxBlocking.podspec
  13. +1 −0 RxBlocking/Platform/AtomicInt.swift
  14. +4 −4 RxBlocking/RunLoopLock.swift
  15. +2 −7 RxCocoa.podspec
  16. +2 −0 RxSwift.podspec
  17. +4 −4 RxSwift/Disposables/AnonymousDisposable.swift
  18. +3 −3 RxSwift/Disposables/BinaryDisposable.swift
  19. +2 −2 RxSwift/Disposables/RefCountDisposable.swift
  20. +3 −3 RxSwift/Disposables/ScheduledDisposable.swift
  21. +9 −15 RxSwift/Disposables/SingleAssignmentDisposable.swift
  22. +3 −3 RxSwift/Observables/Create.swift
  23. +4 −4 RxSwift/Observables/Map.swift
  24. +4 −4 RxSwift/Observables/ObserveOn.swift
  25. +9 −15 RxSwift/Observables/Producer.swift
  26. +4 −4 RxSwift/Observers/ObserverBase.swift
  27. +1 −0 RxSwift/Platform/AtomicInt.swift
  28. +4 −4 RxSwift/Rx.swift
  29. +5 −5 RxSwift/Schedulers/MainScheduler.swift
  30. +3 −3 RxSwift/Schedulers/SchedulerServices+Emulation.swift
  31. +1 −0 RxTest.podspec
  32. +1 −0 Sources/AllTestz/AtomicInt.swift
  33. +1 −0 Sources/AllTestz/AtomicTests.swift
  34. +20 −0 Sources/AllTestz/main.swift
  35. +1 −0 Sources/RxAtomic/RxAtomic.c
  36. +48 −0 Sources/RxAtomic/RxAtomic.h
  37. +48 −0 Sources/RxAtomic/include/RxAtomic.h
  38. +1 −0 Sources/RxBlocking/AtomicInt.swift
  39. +1 −0 Sources/RxSwift/AtomicInt.swift
  40. +1 −0 Tests/Platform/AtomicInt.swift
  41. +184 −0 Tests/RxSwiftTests/AtomicTests.swift
  42. +3 −3 Tests/RxSwiftTests/DisposableTest.swift
  43. +7 −7 Tests/RxSwiftTests/Observable+ObserveOnTests.swift
  44. +3 −1 scripts/package-spm.swift
  45. +1 −0 scripts/validate-headers.swift
View
@@ -258,19 +258,20 @@ custom_categories:
- AnonymousObserver
- ObserverBase
- TailRecursiveSink
- name: RxSwift/Platform/DataStructures
children:
- Bag
- InfiniteSequence
- PriorityQueue
- Queue
- name: RxSwift/Platform
children:
- AtomicInt
- DeprecationWarner
- DispatchQueue+Extensions
- Platform.Darwin
- Platform.Linux
- RecursiveLock
- name: RxSwift/Platform/DataStructures
children:
- Bag
- InfiniteSequence
- PriorityQueue
- Queue
- name: RxSwift/Schedulers
children:
- ConcurrentDispatchQueueScheduler
View
@@ -82,6 +82,7 @@ script:
if [[ ! -z "${BUILD}" ]] ; then
if [[ "${BUILD}" =~ ^pod[[:space:]].* ]]; then
gem install cocoapods --pre --no-rdoc --no-ri --no-document --quiet;
pod repo update;
fi;
eval "${BUILD}";
else
View
@@ -47,17 +47,19 @@ extension Target {
let package = Package(
name: "RxSwift",
products: filterNil([
.library(name: "RxAtomic", targets: ["RxAtomic"]),
.library(name: "RxSwift", targets: ["RxSwift"]),
.library(name: "RxCocoa", targets: ["RxCocoa"]),
.library(name: "RxBlocking", targets: ["RxBlocking"]),
.library(name: "RxTest", targets: ["RxTest"]),
.allTests(),
]),
targets: filterNil([
.target(name: "RxSwift", dependencies: []),
.target(name: "RxAtomic", dependencies: []),
.target(name: "RxSwift", dependencies: ["RxAtomic"]),
.rxCocoa(),
.rxCocoaRuntime(),
.target(name: "RxBlocking", dependencies: ["RxSwift"]),
.target(name: "RxBlocking", dependencies: ["RxSwift", "RxAtomic"]),
.target(name: "RxTest", dependencies: ["RxSwift"]),
.allTests(),
])
View
@@ -0,0 +1,33 @@
//
// AtomicInt.swift
// Platform
//
// Created by Krunoslav Zaher on 10/28/18.
// Copyright © 2018 Krunoslav Zaher. All rights reserved.
//
import RxAtomic
typealias AtomicInt = RxAtomic.AtomicInt
extension AtomicInt {
init(_ initialValue: Int32) {
self.init()
self.initialize(initialValue)
}
@discardableResult
mutating func increment() -> Int32 {
return self.add(1)
}
@discardableResult
mutating func decrement() -> Int32 {
return self.sub(1)
}
mutating func isFlagSet(_ mask: Int32) -> Bool {
return (self.load() & mask) != 0
}
}
@@ -10,34 +10,10 @@
import Darwin
import class Foundation.Thread
import func Foundation.OSAtomicCompareAndSwap32Barrier
import func Foundation.OSAtomicIncrement32Barrier
import func Foundation.OSAtomicDecrement32Barrier
import protocol Foundation.NSCopying
typealias AtomicInt = Int32
fileprivate func castToUInt32Pointer(_ pointer: UnsafeMutablePointer<Int32>) -> UnsafeMutablePointer<UInt32> {
let raw = UnsafeMutableRawPointer(pointer)
return raw.assumingMemoryBound(to: UInt32.self)
}
let AtomicCompareAndSwap = OSAtomicCompareAndSwap32Barrier
let AtomicIncrement = OSAtomicIncrement32Barrier
let AtomicDecrement = OSAtomicDecrement32Barrier
func AtomicOr(_ mask: UInt32, _ theValue : UnsafeMutablePointer<Int32>) -> Int32 {
return OSAtomicOr32OrigBarrier(mask, castToUInt32Pointer(theValue))
}
func AtomicFlagSet(_ mask: UInt32, _ theValue : UnsafeMutablePointer<Int32>) -> Bool {
// just used to create a barrier
OSAtomicXor32OrigBarrier(0, castToUInt32Pointer(theValue))
return (theValue.pointee & Int32(mask)) != 0
}
extension Thread {
static func setThreadLocalStorageValue<T: AnyObject>(_ value: T?, forKey key: NSCopying
) {
static func setThreadLocalStorageValue<T: AnyObject>(_ value: T?, forKey key: NSCopying) {
let currentThread = Thread.current
let threadDictionary = currentThread.threadDictionary
@@ -47,8 +23,8 @@
else {
threadDictionary[key] = nil
}
}
static func getThreadLocalStorageValueForKey<T>(_ key: NSCopying) -> T? {
let currentThread = Thread.current
let threadDictionary = currentThread.threadDictionary
@@ -57,10 +33,4 @@
}
}
extension AtomicInt {
func valueSnapshot() -> Int32 {
return self
}
}
#endif
@@ -8,76 +8,8 @@
#if os(Linux)
import XCTest
import Glibc
import SwiftShims
import class Foundation.Thread
final class AtomicInt {
typealias IntegerLiteralType = Int
fileprivate var value: Int32 = 0
fileprivate var _lock = RecursiveLock()
func lock() {
_lock.lock()
}
func unlock() {
_lock.unlock()
}
func valueSnapshot() -> Int32 {
return value
}
}
extension AtomicInt: ExpressibleByIntegerLiteral {
convenience init(integerLiteral value: Int) {
self.init()
self.value = Int32(value)
}
}
func >(lhs: AtomicInt, rhs: Int32) -> Bool {
return lhs.value > rhs
}
func ==(lhs: AtomicInt, rhs: Int32) -> Bool {
return lhs.value == rhs
}
func AtomicFlagSet(_ mask: UInt32, _ atomic: inout AtomicInt) -> Bool {
atomic.lock(); defer { atomic.unlock() }
return (atomic.value & Int32(mask)) != 0
}
func AtomicOr(_ mask: UInt32, _ atomic: inout AtomicInt) -> Int32 {
atomic.lock(); defer { atomic.unlock() }
let value = atomic.value
atomic.value |= Int32(mask)
return value
}
func AtomicIncrement(_ atomic: inout AtomicInt) -> Int32 {
atomic.lock(); defer { atomic.unlock() }
atomic.value += 1
return atomic.value
}
func AtomicDecrement(_ atomic: inout AtomicInt) -> Int32 {
atomic.lock(); defer { atomic.unlock() }
atomic.value -= 1
return atomic.value
}
func AtomicCompareAndSwap(_ l: Int32, _ r: Int32, _ atomic: inout AtomicInt) -> Bool {
atomic.lock(); defer { atomic.unlock() }
if atomic.value == l {
atomic.value = r
return true
}
return false
}
extension Thread {
static func setThreadLocalStorageValue<T: AnyObject>(_ value: T?, forKey key: String) {
Oops, something went wrong.

0 comments on commit 7610014

Please sign in to comment.