Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"fileScopedDeclarationPrivacy": {
"accessLevel": "private"
},
"indentation": {
"spaces": 4
},
"indentConditionalCompilationBlocks": false,
"indentSwitchCaseLabels": false,
"lineBreakAroundMultilineExpressionChainComponents": false,
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": true,
"lineBreakBeforeEachGenericRequirement": true,
"lineLength": 120,
"maximumBlankLines": 1,
"prioritizeKeepingFunctionOutputTogether": true,
"respectsExistingLineBreaks": true,
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
"AlwaysUseLowerCamelCase": false,
"AmbiguousTrailingClosureOverload": true,
"BeginDocumentationCommentWithOneLineSummary": false,
"DoNotUseSemicolons": true,
"DontRepeatTypeInStaticProperties": true,
"FileScopedDeclarationPrivacy": true,
"FullyIndirectEnum": true,
"GroupNumericLiterals": true,
"IdentifiersMustBeASCII": true,
"NeverForceUnwrap": false,
"NeverUseForceTry": false,
"NeverUseImplicitlyUnwrappedOptionals": false,
"NoAccessLevelOnExtensionDeclaration": false,
"NoAssignmentInExpressions": true,
"NoBlockComments": true,
"NoCasesWithOnlyFallthrough": true,
"NoEmptyTrailingClosureParentheses": true,
"NoLabelsInCasePatterns": false,
"NoLeadingUnderscores": false,
"NoParensAroundConditions": true,
"NoVoidReturnOnFunctionSignature": true,
"OneCasePerLine": true,
"OneVariableDeclarationPerLine": true,
"OnlyOneTrailingClosureArgument": true,
"OrderedImports": false,
"ReturnVoidInsteadOfEmptyTuple": true,
"UseEarlyExits": true,
"UseLetInEveryBoundCaseVariable": false,
"UseShorthandTypeNames": true,
"UseSingleLinePropertyGetter": false,
"UseSynthesizedInitializer": false,
"UseTripleSlashForDocumentationComments": true,
"UseWhereClausesInForLoops": false,
"ValidateDocumentationComments": false
},
"spacesAroundRangeFormationOperators": false,
"tabWidth": 8,
"version": 1
}
24 changes: 0 additions & 24 deletions .swiftformat

This file was deleted.

10 changes: 7 additions & 3 deletions Sources/Prometheus/Counter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import Atomics
import CoreMetrics

/// A counter is a cumulative metric that represents a single monotonically increasing counter whose value
/// can only increase or be ``reset()`` to zero on restart.
/// A counter is a cumulative metric that represents a single monotonically increasing
/// counter whose value can only increase or be ``reset()`` to zero on restart.
///
/// For example, you can use a counter to represent the number of requests served, tasks completed, or errors.
///
Expand Down Expand Up @@ -68,7 +68,11 @@ public final class Counter: Sendable {
while true {
let bits = self.floatAtomic.load(ordering: .relaxed)
let value = Double(bitPattern: bits) + amount
let (exchanged, _) = self.floatAtomic.compareExchange(expected: bits, desired: value.bitPattern, ordering: .relaxed)
let (exchanged, _) = self.floatAtomic.compareExchange(
expected: bits,
desired: value.bitPattern,
ordering: .relaxed
)
if exchanged {
break
}
Expand Down
8 changes: 6 additions & 2 deletions Sources/Prometheus/Gauge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ public final class Gauge: Sendable {
while true {
let bits = self.atomic.load(ordering: .relaxed)
let value = Double(bitPattern: bits) + amount
let (exchanged, _) = self.atomic.compareExchange(expected: bits, desired: value.bitPattern, ordering: .relaxed)
let (exchanged, _) = self.atomic.compareExchange(
expected: bits,
desired: value.bitPattern,
ordering: .relaxed
)
if exchanged {
break
}
Expand All @@ -84,7 +88,7 @@ extension Gauge: CoreMetrics.MeterHandler {
public func set(_ value: Double) {
self.set(to: value)
}

public func set(_ value: Int64) {
self.set(to: Double(value))
}
Expand Down
38 changes: 21 additions & 17 deletions Sources/Prometheus/NIOLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ typealias LockPrimitive = pthread_mutex_t
#endif

@usableFromInline
enum LockOperations { }
enum LockOperations {}

extension LockOperations {
@inlinable
static func create(_ mutex: UnsafeMutablePointer<LockPrimitive>) {
mutex.assertValidAlignment()

#if os(Windows)
#if os(Windows)
InitializeSRWLock(mutex)
#else
#else
var attr = pthread_mutexattr_t()
pthread_mutexattr_init(&attr)
debugOnly {
Expand All @@ -65,43 +65,43 @@ extension LockOperations {

let err = pthread_mutex_init(mutex, &attr)
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
#endif
#endif
}

@inlinable
static func destroy(_ mutex: UnsafeMutablePointer<LockPrimitive>) {
mutex.assertValidAlignment()

#if os(Windows)
#if os(Windows)
// SRWLOCK does not need to be free'd
#else
#else
let err = pthread_mutex_destroy(mutex)
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
#endif
#endif
}

@inlinable
static func lock(_ mutex: UnsafeMutablePointer<LockPrimitive>) {
mutex.assertValidAlignment()

#if os(Windows)
#if os(Windows)
AcquireSRWLockExclusive(mutex)
#else
#else
let err = pthread_mutex_lock(mutex)
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
#endif
#endif
}

@inlinable
static func unlock(_ mutex: UnsafeMutablePointer<LockPrimitive>) {
mutex.assertValidAlignment()

#if os(Windows)
#if os(Windows)
ReleaseSRWLockExclusive(mutex)
#else
#else
let err = pthread_mutex_unlock(mutex)
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
#endif
#endif
}
}

Expand Down Expand Up @@ -188,7 +188,7 @@ final class LockStorage<Value>: ManagedBuffer<Value, LockPrimitive> {
}
}

extension LockStorage: @unchecked Sendable { }
extension LockStorage: @unchecked Sendable {}

/// A threading lock based on `libpthread` instead of `libdispatch`.
///
Expand Down Expand Up @@ -251,7 +251,7 @@ extension NIOLock {
}

@inlinable
func withLockVoid(_ body: () throws -> Void) rethrows -> Void {
func withLockVoid(_ body: () throws -> Void) rethrows {
try self.withLock(body)
}
}
Expand All @@ -272,6 +272,10 @@ extension UnsafeMutablePointer {
/// https://forums.swift.org/t/support-debug-only-code/11037 for a discussion.
@inlinable
internal func debugOnly(_ body: () -> Void) {
assert({ body(); return true }())
assert(
{
body()
return true
}()
)
}

Loading