From 0c2b078aa3deba3e553a2cdc99b1e731c4b4dc24 Mon Sep 17 00:00:00 2001 From: Jared Sinclair Date: Mon, 15 Apr 2024 14:03:44 -0500 Subject: [PATCH] Synchronize access to Datadog.verbosityLevel fixing issue #1549 Explicitly declares Sendable conformance for ReadWriteLock. Uses ReadWriteLock to Synchronize access to Datadog.verbosityLevel. --- DatadogCore/Sources/Datadog.swift | 9 ++++++++- DatadogInternal/Sources/Concurrency/ReadWriteLock.swift | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/DatadogCore/Sources/Datadog.swift b/DatadogCore/Sources/Datadog.swift index 272f53d588..70740e327d 100644 --- a/DatadogCore/Sources/Datadog.swift +++ b/DatadogCore/Sources/Datadog.swift @@ -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(wrappedValue: nil) /// Returns `true` if the Datadog SDK is already initialized, `false` otherwise. /// diff --git a/DatadogInternal/Sources/Concurrency/ReadWriteLock.swift b/DatadogInternal/Sources/Concurrency/ReadWriteLock.swift index bb46135609..5093712c7f 100644 --- a/DatadogInternal/Sources/Concurrency/ReadWriteLock.swift +++ b/DatadogInternal/Sources/Concurrency/ReadWriteLock.swift @@ -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 { +public final class ReadWriteLock: @unchecked Sendable { /// The wrapped value. private var value: Value