Skip to content

Commit

Permalink
fix: Works around a Linux specific compilation issue
Browse files Browse the repository at this point in the history
This issue occurs against newer Swift development toolchains.

PassiveLogic#3
  • Loading branch information
clackary committed Oct 10, 2024
1 parent 72f330b commit 4070ce5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class BatchLogRecordProcessor : LogRecordProcessor {
}
}

private class BatchWorker : Thread {
private class BatchWorker {
let logRecordExporter : LogRecordExporter
let scheduleDelay : TimeInterval
let maxQueueSize : Int
Expand All @@ -49,7 +49,10 @@ private class BatchWorker : Thread {
private let cond = NSCondition()
var logRecordList = [ReadableLogRecord]()
var queue : OperationQueue

// TODO: Workaround for the following compiler issue, and can be removed once resolved
// https://github.com/swiftlang/swift/issues/76752
private let _thread : Thread

init(logRecordExporter: LogRecordExporter,
scheduleDelay: TimeInterval,
exportTimeout: TimeInterval,
Expand All @@ -67,8 +70,17 @@ private class BatchWorker : Thread {
queue = OperationQueue()
queue.name = "BatchWorker Queue"
queue.maxConcurrentOperationCount = 1
self._thread = Thread()
}


func start() {
self._thread.start()
}

func cancel() {
self._thread.cancel()
}

func emit(logRecord: ReadableLogRecord) {
cond.lock()
defer { cond.unlock()}
Expand All @@ -84,7 +96,7 @@ private class BatchWorker : Thread {
}
}

override func main() {
func main() {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
repeat {
autoreleasepool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public struct BatchSpanProcessor: SpanProcessor {
/// BatchWorker is a thread that batches multiple spans and calls the registered SpanExporter to export
/// the data.
/// The list of batched data is protected by a NSCondition which ensures full concurrency.
private class BatchWorker: Thread {
private class BatchWorker {
let spanExporter: SpanExporter
let scheduleDelay: TimeInterval
let maxQueueSize: Int
Expand All @@ -67,7 +67,10 @@ private class BatchWorker: Thread {
private let cond = NSCondition()
var spanList = [ReadableSpan]()
var queue: OperationQueue

// TODO: Workaround for the following compiler issue, and can be removed once resolved
// https://github.com/swiftlang/swift/issues/76752
private let _thread: Thread

init(spanExporter: SpanExporter, scheduleDelay: TimeInterval, exportTimeout: TimeInterval, maxQueueSize: Int, maxExportBatchSize: Int, willExportCallback: ((inout [SpanData]) -> Void)?) {
self.spanExporter = spanExporter
self.scheduleDelay = scheduleDelay
Expand All @@ -79,8 +82,17 @@ private class BatchWorker: Thread {
queue = OperationQueue()
queue.name = "BatchWorker Queue"
queue.maxConcurrentOperationCount = 1
self._thread = Thread()
}


func start() {
self._thread.start()
}

func cancel() {
self._thread.cancel()
}

func addSpan(span: ReadableSpan) {
cond.lock()
defer { cond.unlock() }
Expand All @@ -99,7 +111,7 @@ private class BatchWorker: Thread {
}

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
override func main() {
func main() {
repeat {
autoreleasepool {
var spansCopy: [ReadableSpan]
Expand All @@ -117,7 +129,7 @@ private class BatchWorker: Thread {
} while true
}
#else
override func main() {
func main() {
repeat {
var spansCopy: [ReadableSpan]
cond.lock()
Expand Down

0 comments on commit 4070ce5

Please sign in to comment.