-
Notifications
You must be signed in to change notification settings - Fork 469
[FreeBSD] support FreeBSD #861
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 all commits
b55398e
4faf129
a1c8b47
d5cd841
709fe83
a654472
f642f48
17ed7bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,6 +293,52 @@ _dispatch_workq_count_runnable_workers(dispatch_workq_monitor_t mon) | |
|
||
_dispatch_unfair_lock_unlock(&mon->registered_tid_lock); | ||
} | ||
#elif defined(__FreeBSD__) | ||
#include <sys/sysctl.h> | ||
#include <sys/proc.h> | ||
#include <sys/user.h> | ||
|
||
static void | ||
_dispatch_workq_count_runnable_workers(dispatch_workq_monitor_t mon) | ||
{ | ||
struct kinfo_proc kp[WORKQ_MAX_TRACKED_TIDS]; | ||
size_t size; | ||
int count, runners = 0; | ||
int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD, (int)getpid()}; | ||
|
||
// get size we need | ||
if (sysctl(mib, 4, NULL, &size, NULL, 0) < 0) { | ||
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. I wonder if we should use #define ARRAY_SIZEOF(array) (sizeof((array))/sizeof(*(array))) 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. I don't really think it's a good idea to introduce a macro, especially just for one place. Although it makes it more readable, but I think it is reasonable to expect the next person who need to change this line are already familiar with the correct usage of |
||
_dispatch_debug("workq: failed to get size for kinfo_proc[] from sysctll"); | ||
return; | ||
} | ||
|
||
// only care about up to WORKQ_MAX_TRACKED_TIDS threads | ||
size = MIN(sizeof(kp), size); | ||
|
||
if (sysctl(mib, 4, kp, &size, NULL, 0) < 0) { | ||
_dispatch_debug("workq: failed to get kinfo_proc[] from sysctl"); | ||
return; | ||
} | ||
|
||
count = (int)(size / sizeof(struct kinfo_proc)); | ||
|
||
_dispatch_unfair_lock_lock(&mon->registered_tid_lock); | ||
|
||
for (int i = 0; i < mon->num_registered_tids; ++i) { | ||
dispatch_tid tid = mon->registered_tids[i]; | ||
for (int j = 0; i < count; ++i) { | ||
if ((dispatch_tid)kp[j].ki_tid != tid) { continue; } | ||
if (kp[j].ki_stat == SRUN || kp[j].ki_stat == SIDL) { | ||
++runners; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
mon->num_runnable = runners; | ||
|
||
_dispatch_unfair_lock_unlock(&mon->registered_tid_lock); | ||
} | ||
#else | ||
#error must define _dispatch_workq_count_runnable_workers | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,8 +124,17 @@ extension DispatchSource { | |
public static let exit = ProcessEvent(rawValue: 0x80000000) | ||
public static let fork = ProcessEvent(rawValue: 0x40000000) | ||
public static let exec = ProcessEvent(rawValue: 0x20000000) | ||
#if os(FreeBSD) | ||
public static let track = ProcessEvent(rawValue: 0x00000001) | ||
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. Why the different name? Should we not be using the name names to maintain source consistency? 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 is because 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. Sure, having an extended FreeBSD only option is fine, but this does remove the 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. Sorry, I should've add more context in my previous reply.
on the other hand, |
||
#else | ||
public static let signal = ProcessEvent(rawValue: 0x08000000) | ||
#endif | ||
|
||
#if os(FreeBSD) | ||
public static let all: ProcessEvent = [.exit, .fork, .exec, .track] | ||
#else | ||
public static let all: ProcessEvent = [.exit, .fork, .exec, .signal] | ||
#endif | ||
} | ||
#endif | ||
|
||
|
@@ -224,7 +233,7 @@ extension DispatchSource { | |
return DispatchSource(source: source) as DispatchSourceUserDataReplace | ||
} | ||
|
||
#if !os(Linux) && !os(Android) && !os(Windows) && !os(OpenBSD) | ||
#if !os(Linux) && !os(Android) && !os(Windows) && !os(OpenBSD) && !os(FreeBSD) | ||
public class func makeFileSystemObjectSource(fileDescriptor: Int32, eventMask: FileSystemEvent, queue: DispatchQueue? = nil) -> DispatchSourceFileSystemObject { | ||
let source = dispatch_source_create(_swift_dispatch_source_type_VNODE(), UInt(fileDescriptor), eventMask.rawValue, queue?.__wrapped) | ||
return DispatchSource(source: source) as DispatchSourceFileSystemObject | ||
|
@@ -293,7 +302,7 @@ extension DispatchSourceMemoryPressure { | |
#if !os(Linux) && !os(Android) && !os(Windows) && !os(OpenBSD) | ||
extension DispatchSourceProcess { | ||
public var handle: pid_t { | ||
return pid_t(dispatch_source_get_handle(self as! DispatchSource)) | ||
return pid_t(CDispatch.dispatch_source_get_handle((self as! DispatchSource).__wrapped)) | ||
} | ||
|
||
public var data: DispatchSource.ProcessEvent { | ||
|
Uh oh!
There was an error while loading. Please reload this page.