Skip to content

Instantly share code, notes, and snippets.

View timboudreau's full-sized avatar

Tim Boudreau timboudreau

View GitHub Profile
@timboudreau
timboudreau / IOPolicies.swift
Created September 14, 2025 08:30
A friendly wrapper around `setiopolicy_np` for iOS / Mac OS
/// A friendly wrapper around `setiopolicy_np`.
public enum IOPolicies {
case DontResolveSymlinks
case DiskIONormal
case DiskIOPassive
case DiskIOThrottled
case DiskIOImportant
case MaterializeVirtualFiles
case DontMaterializeVirtualFiles
case BackgroundIOImportant
@timboudreau
timboudreau / AppDelegate.swift
Last active February 4, 2026 05:29
nonisolated and isolated in AppDelegate
fileprivate final class MixenAppDelegate: NSObject, UIApplicationDelegate, MXMetricManagerSubscriber {
nonisolated let registered = AtomicBool()
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Get this out of the critial path of startup, or we will get passed metrics packets to
// process before the main UI is on-screen
if OnboardingState.initial.isReadyForUse {
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 75) {
self.register()
}
}
@timboudreau
timboudreau / SwiftRustAtomics.swift
Created February 18, 2026 05:51
An API for atomic integers in Swift that is not complete pants
/*
We generate two implementations for each integer type (optionally including UInt128, which won't compile
on MacOS < 15, so it's not there by default), including size_t and ptrdiff_t (aka Rust's isize):
* SwiftAtomic$TYPE - A class type which owns the allocation and implements SwiftAtomicInteger
* Atomic$TYPEPointer - A struct which consumes an UnsafeMutablePointer<$TYPE> and does *not* involve a
reference-counted class type (but the code that instantiates it is entirely responsible for ensuring
the pointee is not dropped, and for explicitly dropping it in deinit)
For the second, it would be nicer to implement IntegerAtomic *directly* on UnsafeMutablePointer, but Swift
@timboudreau
timboudreau / SwiftAtomicReference.swift
Created February 23, 2026 01:59
An atomic object reference in Swift (using Rust for the actual atomic operations)
/// An atomic reference to an object.
public final class SwiftAtomicReference<T : AnyObject> : @unchecked Sendable where T: Sendable {
private let pointer: UnsafeMutablePointer<size_t>
public var value : T {
get {
load()
} set(val) {
store(val)
}