-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a307d86
commit 1619320
Showing
28 changed files
with
214 additions
and
71 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
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
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,104 @@ | ||
// | ||
// Copyright (c) 2023-Present, Okta, Inc. and/or its affiliates. All rights reserved. | ||
// The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") | ||
// | ||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// | ||
// See the License for the specific language governing permissions and limitations under the License. | ||
// | ||
|
||
import Foundation | ||
|
||
#if canImport(Darwin) | ||
import Darwin | ||
#elseif canImport(Glibc) | ||
import Glibc | ||
#elseif canImport(Musl) | ||
import Musl | ||
#elseif canImport(Bionic) | ||
import Bionic | ||
#else | ||
#error("Unsupported platform") | ||
#endif | ||
|
||
// **Note:** It would be preferable to use OSAllocatedUnfairLock for this, but this would mean dropping support for older OS versions. While this approach is safe, OSAllocatedUnfairLock provides more features we might need in the future. | ||
// | ||
// If the minimum supported version of this SDK is to increase in the future, this class should be removed and replaced with OSAllocatedUnfairLock. | ||
final class Lock: NSLocking { | ||
#if canImport(Darwin) | ||
private typealias LockType = os_unfair_lock | ||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) | ||
private typealias LockType = pthread_mutex_t | ||
#else | ||
#error("Unsupported platform") | ||
#endif | ||
|
||
private let _lock: UnsafeMutablePointer<LockType> = { | ||
let result = UnsafeMutablePointer<LockType>.allocate(capacity: 1) | ||
|
||
#if canImport(Darwin) | ||
result.initialize(to: os_unfair_lock()) | ||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) | ||
let status = pthread_mutex_init(result, nil) | ||
precondition(status == 0, "pthread_mutex_init failed") | ||
#else | ||
#error("Unsupported platform") | ||
#endif | ||
|
||
return result | ||
}() | ||
|
||
deinit { | ||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic) | ||
let status = pthread_mutex_destroy(_lock) | ||
precondition(status == 0, "pthread_mutex_destroy failed") | ||
#endif | ||
_lock.deinitialize(count: 1) | ||
_lock.deallocate() | ||
} | ||
|
||
func lock() { | ||
#if canImport(Darwin) | ||
os_unfair_lock_lock(_lock) | ||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) | ||
let status = pthread_mutex_lock(_lock) | ||
precondition(status == 0, "pthread_mutex_lock failed") | ||
#else | ||
#error("Unsupported platform") | ||
#endif | ||
} | ||
|
||
func tryLock() -> Bool { | ||
#if canImport(Darwin) | ||
return os_unfair_lock_trylock(_lock) | ||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) | ||
return pthread_mutex_trylock(_lock) == 0 | ||
#else | ||
#error("Unsupported platform") | ||
#endif | ||
} | ||
|
||
func unlock() { | ||
#if canImport(Darwin) | ||
os_unfair_lock_unlock(_lock) | ||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) | ||
let status = pthread_mutex_unlock(_lock) | ||
precondition(status == 0, "pthread_mutex_unlock failed") | ||
#else | ||
#error("Unsupported platform") | ||
#endif | ||
} | ||
|
||
#if !canImport(Darwin) | ||
func withLock<T>(_ body: () throws -> T) rethrows -> T { | ||
self.lock() | ||
defer { | ||
self.unlock() | ||
} | ||
return try body() | ||
} | ||
#endif | ||
} |
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
33 changes: 33 additions & 0 deletions
33
Sources/AuthFoundation/Utilities/URL+InternalExtensions.swift
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,33 @@ | ||
// | ||
// Copyright (c) 2024-Present, Okta, Inc. and/or its affiliates. All rights reserved. | ||
// The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") | ||
// | ||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// | ||
// See the License for the specific language governing permissions and limitations under the License. | ||
// | ||
|
||
import Foundation | ||
|
||
extension URL { | ||
@inlinable | ||
// Workaround to address a known bug with URL.appendingPathComponent on Linux. | ||
// https://github.com/apple/swift-corelibs-foundation/issues/4849 | ||
func appendingComponent(_ component: String) -> URL { | ||
#if os(Linux) | ||
var components = URLComponents(url: self, resolvingAgainstBaseURL: true)! | ||
if !components.path.hasSuffix("/") { | ||
components.path.append("/") | ||
} | ||
components.path.append(component) | ||
return components.url! | ||
#else | ||
var result = self | ||
result.appendPathComponent(component) | ||
return result | ||
#endif | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.