-
Notifications
You must be signed in to change notification settings - Fork 28
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
2 changed files
with
125 additions
and
0 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,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 | ||
} | ||
} | ||
|
||
|
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,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 {} | ||
} |