-
Notifications
You must be signed in to change notification settings - Fork 129
[DRAFT] ProcessID, Signal, SignalSet, TaskInfo, ResourceUsageInfo #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
ad80d0f
0ebaa29
544fc8a
881a8ad
0c32e4e
c96a3e6
a051d71
153e5d3
e8b5ab4
9edaf16
5bc82a4
9830717
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| This source file is part of the Swift System open source project | ||
|
|
||
| Copyright (c) 2020 Apple Inc. and the Swift System project authors | ||
| Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
|
||
| See https://swift.org/LICENSE.txt for license information | ||
| */ | ||
|
|
||
| #ifdef __MACH__ | ||
| #include "libproc.h" | ||
| #else | ||
| #error "whoops" | ||
| #endif | ||
|
|
||
| // |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,3 +16,7 @@ | |
| #if defined(_WIN32) | ||
| #include <CSystemWindows.h> | ||
| #endif | ||
|
|
||
| #ifdef __MACH__ | ||
| #include <CSystemDarwin.h> | ||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
|
|
||
| // FIXME(DO NOT MERGE): We need to find a way around this. We want to declare | ||
| // a typealias to a struct from a header, but don't want downstream to import | ||
| // Darwin or the whole header just for that. | ||
| // | ||
| import Darwin | ||
| extension CInterop { | ||
| public typealias PID = Int32 | ||
| public typealias ProcTaskInfo = proc_taskinfo // FIXME | ||
| public typealias RUsageInfo = rusage_info_current // FIXME | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have the option to just go with the original type names here, but I think it's still nice to have these typealiases. |
||
| } | ||
|
|
||
| public struct ProcessID: RawRepresentable, Hashable, Codable { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to me that this is more of a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This struct is the handle to the process, it's very much like a file descriptor. It's not "safe" to assume it's still valid after a process is torn down, etc. I've been thinking that a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think |
||
| /// The raw C process id. | ||
| @_alwaysEmitIntoClient | ||
| public let rawValue: CInterop.PID | ||
|
|
||
| /// Creates a strongly-typed process id from a raw C pid | ||
| @_alwaysEmitIntoClient | ||
| public init(rawValue: CInterop.PID) { self.rawValue = rawValue } | ||
|
|
||
| fileprivate init(_ rawValue: CInterop.PID) { self.init(rawValue: rawValue) } | ||
|
|
||
| } | ||
|
|
||
| extension ProcessID { | ||
| public struct TaskInfo: RawRepresentable/*, Hashable, Codable*/ { | ||
| /// The raw C process id. | ||
| @_alwaysEmitIntoClient | ||
| public let rawValue: CInterop.ProcTaskInfo | ||
|
|
||
| /// Creates a strongly-typed process id from a raw C pid | ||
| @_alwaysEmitIntoClient | ||
| public init(rawValue: CInterop.ProcTaskInfo) { self.rawValue = rawValue } | ||
|
|
||
| fileprivate init(_ rawValue: CInterop.ProcTaskInfo) { self.init(rawValue: rawValue) } | ||
|
|
||
| } | ||
|
|
||
| public struct ResourceUsageInfo: RawRepresentable/*, Hashable, Codable*/ { | ||
| /// The raw C process id. | ||
| @_alwaysEmitIntoClient | ||
| public let rawValue: CInterop.RUsageInfo | ||
|
|
||
| /// Creates a strongly-typed process id from a raw C pid | ||
| @_alwaysEmitIntoClient | ||
| public init(rawValue: CInterop.RUsageInfo) { self.rawValue = rawValue } | ||
|
|
||
| fileprivate init(_ rawValue: CInterop.RUsageInfo) { self.init(rawValue: rawValue) } | ||
|
|
||
| fileprivate static var blank: ResourceUsageInfo { ResourceUsageInfo(rusage_info_current()) } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out we should just import Darwin! Since System isn't an overlay, it doesn't need to reexport the module, and merely importing it won't pollute the client namespace with C junk. 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use
Darwin's types though? Also, can we do this with ourCSystemmodule as well (which is needed for Linux, sincelibCisn'tlibSystem).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so -- if people only import System, they will still be able to refer to these types by one of their System typealiases (such as the ones in CInterop or RawValue). (They can't spell
Darwin.foounless they import it.)CSystemis trickier, because it shouldn't be a public module, so we should continue to import it@_implementationOnly.