Skip to content

Commit 2b6e31e

Browse files
MrLotUktoso
authored andcommitted
Expose lock functionality
1 parent f5ed78c commit 2b6e31e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Sources/CoreMetrics/Metrics.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,22 @@ public enum MetricsSystem {
382382
fileprivate static var _factory: MetricsFactory = NOOPMetricsHandler.instance
383383
fileprivate static var initialized = false
384384

385+
/// Acquire a writer lock for the duration of the given block.
386+
///
387+
/// - Parameter body: The block to execute while holding the lock.
388+
/// - Returns: The value returned by the block.
389+
public static func withWriterLock<T>(_ body: () throws -> T) rethrows -> T {
390+
return try self.lock.withWriterLock(body)
391+
}
392+
393+
/// Acquire a reader lock for the duration of the given block.
394+
///
395+
/// - Parameter body: The block to execute while holding the lock.
396+
/// - Returns: The value returned by the block.
397+
public static func withReaderLock<T>(_ body: () throws -> T) rethrows -> T {
398+
return try self.lock.withReaderLock(body)
399+
}
400+
385401
/// `bootstrap` is an one-time configuration function which globally selects the desired metrics backend
386402
/// implementation. `bootstrap` can be called at maximum once in any given program, calling it more than once will
387403
/// lead to undefined behaviour, most likely a crash.

0 commit comments

Comments
 (0)