Skip to content

Commit

Permalink
Synchronize access to Datadog.verbosityLevel fixing issue DataDog#1549
Browse files Browse the repository at this point in the history
Explicitly declares Sendable conformance for ReadWriteLock.

Uses ReadWriteLock to Synchronize access to Datadog.verbosityLevel.
  • Loading branch information
jaredsinclair committed Apr 19, 2024
1 parent b63af60 commit 0c2b078
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion DatadogCore/Sources/Datadog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,14 @@ public enum Datadog {
/// Verbosity level of Datadog SDK. Can be used for debugging purposes.
/// If set, internal events occuring inside SDK will be printed to debugger console if their level is equal or greater than `verbosityLevel`.
/// Default is `nil`.
public static var verbosityLevel: CoreLoggerLevel? = nil
public static var verbosityLevel: CoreLoggerLevel? {
get { _verbosityLevel.wrappedValue }
set { _verbosityLevel.wrappedValue = newValue }
}

/// The backing storage for `verbosityLevel`, ensuring efficient synchronized
/// read/write access to the shared value.
private static let _verbosityLevel = ReadWriteLock<CoreLoggerLevel?>(wrappedValue: nil)

/// Returns `true` if the Datadog SDK is already initialized, `false` otherwise.
///
Expand Down
2 changes: 1 addition & 1 deletion DatadogInternal/Sources/Concurrency/ReadWriteLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation
/// An additional method `mutate` allow to safely mutate the value in-place (to read it
/// and write it while obtaining the lock only once).
@propertyWrapper
public final class ReadWriteLock<Value> {
public final class ReadWriteLock<Value>: @unchecked Sendable {
/// The wrapped value.
private var value: Value

Expand Down

0 comments on commit 0c2b078

Please sign in to comment.