-
Notifications
You must be signed in to change notification settings - Fork 470
[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
Changes from 1 commit
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 |
---|---|---|
|
@@ -247,6 +247,51 @@ _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; | ||
michael-yuji marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 = size > sizeof(kp) ? sizeof(kp) : size; | ||
michael-yuji marked this conversation as resolved.
Show resolved
Hide resolved
|
||
count = (int)(size / sizeof(struct kinfo_proc)); | ||
|
||
if (sysctl(mib, 4, kp, &size, NULL, 0) < 0) { | ||
_dispatch_debug("workq: failed to get kinfo_proc[] from sysctl"); | ||
return; | ||
} | ||
|
||
_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 | ||
|
Uh oh!
There was an error while loading. Please reload this page.