Skip to content

Commit

Permalink
Fix TSAN issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
kzaher committed Apr 1, 2019
1 parent 7a8a116 commit cce95dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
10 changes: 5 additions & 5 deletions Tests/RxSwiftTests/Observable+ConcatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,11 @@ extension ObservableConcatTest {
let elements = try! generateCollection(0) { i in
Observable.just(i, scheduler: CurrentThreadScheduler.instance)
}
.take(10000)
.take(100)
.toBlocking()
.toArray()

XCTAssertEqual(elements, Array(0 ..< 10000))
XCTAssertEqual(elements, Array(0 ..< 100))
XCTAssertEqual(maxTailRecursiveSinkStackSize, 1)
}

Expand All @@ -644,12 +644,12 @@ extension ObservableConcatTest {
let elements = try! generateSequence(0) { i in
Observable.just(i, scheduler: CurrentThreadScheduler.instance)
}
.take(10000)
.take(100)
.toBlocking()
.toArray()

XCTAssertEqual(elements, Array(0 ..< 10000))
XCTAssertTrue(maxTailRecursiveSinkStackSize > 1000)
XCTAssertEqual(elements, Array(0 ..< 100))
XCTAssertTrue(maxTailRecursiveSinkStackSize > 10)
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ class PrimitiveHotObservable<ElementType> : ObservableType {
typealias Events = Recorded<E>
typealias Observer = AnyObserver<E>

var subscriptions = [Subscription]()
let observers = PublishSubject<ElementType>()
var _subscriptions = [Subscription]()
let _observers = PublishSubject<ElementType>()

public var subscriptions: [Subscription] {
lock.lock()
defer { lock.unlock() }
return _subscriptions
}

let lock = RecursiveLock()

Expand All @@ -30,17 +36,17 @@ class PrimitiveHotObservable<ElementType> : ObservableType {
func on(_ event: Event<E>) {
lock.lock()
defer { lock.unlock() }
observers.on(event)
_observers.on(event)
}

func subscribe<O : ObserverType>(_ observer: O) -> Disposable where O.E == E {
lock.lock()
defer { lock.unlock() }

let removeObserver = observers.subscribe(observer)
subscriptions.append(SubscribedToHotObservable)
let removeObserver = _observers.subscribe(observer)
_subscriptions.append(SubscribedToHotObservable)

let i = self.subscriptions.count - 1
let i = self._subscriptions.count - 1

var count = 0

Expand All @@ -52,7 +58,7 @@ class PrimitiveHotObservable<ElementType> : ObservableType {
count += 1
assert(count == 1)

self.subscriptions[i] = UnsunscribedFromHotObservable
self._subscriptions[i] = UnsunscribedFromHotObservable
}
}
}
Expand Down

0 comments on commit cce95dd

Please sign in to comment.