Skip to content

Commit

Permalink
Add Update and Signpost support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Mar 16, 2024
1 parent 35aac35 commit 263a51b
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Sources/OpenSwiftUI/Core/Log/Signpost.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Signpost.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: WIP
// ID: 34756F646CF7AC3DBE2A8E0B344C962F

import os.signpost

struct Signpost {
private let style: Style
private let stability: Stability

// TODO
var isEnabled: Bool {
switch stability {
case .disabled, .verbose, .debug:
return false
case .published:
return true
}
}

static let viewHost = Signpost(style: .kdebug(0), stability: .published)
}

extension Signpost {
private enum Style {
case kdebug(UInt8)
case os_log(StaticString)
}

private enum Stability: Hashable {
case disabled
case verbose
case debug
case published
}
}


83 changes: 83 additions & 0 deletions Sources/OpenSwiftUI/Core/Update/Update.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// Update.swift
// OpenSwiftUI
//
// Status: WIP
// ID: EA173074DA35FA471DC70643259B7E74

internal import COpenSwiftUI
internal import OpenGraphShims

extension MovableLock {
@inline(__always)
func withLock<R>(_ body: () -> R) -> R {
lock()
defer { unlock() }
return body()
}
}

enum Update {
static let trackHost: AnyObject = TraceHost()
private static let lock = MovableLock.create()
private static var depth = 0
private static var actions: [() -> Void] = []

static func begin() {
lock.lock()
depth += 1
if depth == 1 {
guard Signpost.viewHost.isEnabled else {
return
}
// TODO: Signpost
}
}

static func end() {
if depth == 1 {
dispatchActions()
// TODO: Signpost
}
depth -= 1
lock.unlock()
}

static func enqueueAction(_ action: @escaping () -> Void) {
begin()
actions.append(action)
end()
}

static func ensure<Value>(_ body: () -> Value) throws -> Value {
lock.withLock {
if depth == 0 {
begin()
}
defer {
if depth == 0 {
end()
}
}
return body()
}
}

@inlinable
static func dispatchActions() {
// FIXME
for action in actions {
action()
}
}

@inlinable
static func syncMain(_ body: () -> Void) {
// TODO
fatalError("TODO")
}
}

extension Update {
private class TraceHost {}
}

0 comments on commit 263a51b

Please sign in to comment.