-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RUM-1053 Make Logger Sendable for Swift 6 concurrency #2035
Changes from all commits
99d25c4
a2d7092
bd37fb8
1691d07
6ae80cc
79470bc
c8c1e79
a3d8423
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-Present Datadog, Inc. | ||
*/ | ||
|
||
import Foundation | ||
import DatadogInternal | ||
|
||
/// A thread-safe container for managing attributes in a key-value format. | ||
/// This class allows concurrent access and modification of attributes, ensuring data consistency | ||
/// through the use of a `ReadWriteLock`. It is designed to be used in scenarios where attributes | ||
/// need to be safely managed across multiple threads or tasks. | ||
internal final class SynchronizedAttributes: Sendable { | ||
/// The underlying dictionary of attributes, wrapped in a `ReadWriteLock` to ensure thread safety. | ||
private let attributes: ReadWriteLock<[String: Encodable]> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /question We are not using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, makes sense π |
||
|
||
/// Initializes a new instance of `SynchronizedAttributes` with the provided dictionary. | ||
/// | ||
/// - Parameter attributes: A dictionary of initial attributes. | ||
init(attributes: [String: Encodable]) { | ||
self.attributes = .init(wrappedValue: attributes) | ||
} | ||
|
||
/// Adds or updates an attribute in the container. | ||
/// | ||
/// - Parameters: | ||
/// - key: The key associated with the attribute. | ||
/// - value: The value to associate with the key. | ||
func addAttribute(key: AttributeKey, value: AttributeValue) { | ||
attributes.mutate { $0[key] = value } | ||
} | ||
|
||
/// Removes an attribute from the container. | ||
/// | ||
/// - Parameter key: The key of the attribute to remove. | ||
func removeAttribute(forKey key: AttributeKey) { | ||
attributes.mutate { $0.removeValue(forKey: key) } | ||
} | ||
|
||
/// Retrieves the current dictionary of attributes. | ||
/// | ||
/// - Returns: A dictionary containing all the attributes. | ||
func getAttributes() -> [String: Encodable] { | ||
return attributes.wrappedValue | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π‘ not needed anymore after we dropped iOS 11