-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the
logLevel
property changeable (#5)
* Make the `logLevel` property changable * Update `CHANGELOG.md`
- Loading branch information
1 parent
83d5737
commit e649dda
Showing
5 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// log | ||
// Copyright © 2024 Space Code. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - Atomic | ||
|
||
/// The Atomic class is designed to provide thread-safe access to a mutable value. | ||
final class Atomic<Value> { | ||
// MARK: Properties | ||
|
||
/// NSLock instance for synchronization. | ||
private let lock = NSLock() | ||
/// The actual mutable value. | ||
private var _value: Value | ||
|
||
/// Computed property to get and set the value atomically | ||
var value: Value { | ||
get { lock.synchronized { _value } } | ||
set { lock.synchronized { _value = newValue }} | ||
} | ||
|
||
// MARK: Initialization | ||
|
||
/// Initializes the Atomic instance with an initial value. | ||
init(value: Value) { | ||
_value = value | ||
} | ||
} | ||
|
||
// MARK: - Extensions | ||
|
||
private extension NSLock { | ||
/// Synchronizes a code block using the NSLock instance. | ||
/// This helps ensure that only one thread can access the critical section at a time. | ||
func synchronized<T>(block: () throws -> T) rethrows -> T { | ||
lock() | ||
defer { unlock() } | ||
return try block() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters