-
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.
- Loading branch information
Showing
5 changed files
with
89 additions
and
120 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Foundation | ||
|
||
// Workaround for Calendar not being thread-safe on linux | ||
|
||
@frozen | ||
@usableFromInline | ||
struct CalculationCalendar { | ||
@usableFromInline | ||
let calendar: Calendar | ||
#if !canImport(Darwin) | ||
@usableFromInline | ||
let calendarLock = DispatchQueue(label: "de.sersoft.swiftyholidays.calculation-calendar.lock") | ||
#endif | ||
|
||
@inlinable | ||
func withCalendar<T>(do work: (Calendar) throws -> T) rethrows -> T { | ||
#if canImport(Darwin) | ||
try work(calendar) | ||
#else | ||
dispatchPrecondition(condition: .notOnQueue(calendarLock)) | ||
return try calendarLock.sync { try work(calendar) } | ||
#endif | ||
} | ||
} | ||
|
||
#if canImport(Darwin) | ||
extension CalculationCalendar: Sendable {} | ||
#else | ||
extension CalculationCalendar: @unchecked Sendable {} | ||
#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
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