-
Notifications
You must be signed in to change notification settings - Fork 469
Fix FreeBSD support #561
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?
Fix FreeBSD support #561
Changes from all commits
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 |
---|---|---|
|
@@ -389,15 +389,23 @@ _dispatch_kevent_print_error(dispatch_kevent_t ke) | |
case 0: | ||
return; | ||
case ERANGE: /* A broken QoS was passed to kevent_id() */ | ||
#if defined(__APPLE__) | ||
DISPATCH_INTERNAL_CRASH(ke->qos, "Invalid kevent priority"); | ||
#else | ||
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. kevent on FreeBSD won't return ERANGE here, so we shouldn't need to trap this. |
||
DISPATCH_INTERNAL_CRASH(0, "Invalid kevent priority"); | ||
#endif | ||
default: | ||
#if HAVE_MACH | ||
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 actually don't need to wrap HAVE_MACH here; we can remove the conditional in |
||
// log the unexpected error | ||
_dispatch_bug_kevent_client("kevent", _evfiltstr(ke->filter), | ||
!ke->udata ? NULL : | ||
ke->flags & EV_DELETE ? "delete" : | ||
ke->flags & EV_ADD ? "add" : | ||
ke->flags & EV_ENABLE ? "enable" : "monitor", | ||
(int)ke->data, ke->ident, ke->udata, du); | ||
#else | ||
break; | ||
#endif | ||
} | ||
} | ||
|
||
|
@@ -591,7 +599,6 @@ _dispatch_kq_create(intptr_t *fd_ptr) | |
guardid_t guard = (uintptr_t)fd_ptr; | ||
kqfd = guarded_kqueue_np(&guard, GUARD_CLOSE | GUARD_DUP); | ||
#else | ||
(void)guard_ptr; | ||
kqfd = kqueue(); | ||
#endif | ||
if (kqfd == -1) { | ||
|
@@ -743,7 +750,7 @@ _dispatch_kq_poll(dispatch_wlh_t wlh, dispatch_kevent_t ke, int n, | |
switch (err) { | ||
case ENOMEM: | ||
_dispatch_temporary_resource_shortage(); | ||
/* FALLTHROUGH */ | ||
DISPATCH_FALLTHROUGH; | ||
case EINTR: | ||
goto retry; | ||
case EBADF: | ||
|
@@ -754,7 +761,7 @@ _dispatch_kq_poll(dispatch_wlh_t wlh, dispatch_kevent_t ke, int n, | |
(flags & KEVENT_FLAG_DYNAMIC_KQ_MUST_EXIST)) { | ||
return 0; | ||
} | ||
/* FALLTHROUGH */ | ||
DISPATCH_FALLTHROUGH; | ||
#endif // DISPATCH_USE_KEVENT_WORKLOOP | ||
default: | ||
DISPATCH_CLIENT_CRASH(err, "Unexpected error from kevent"); | ||
|
@@ -860,7 +867,6 @@ _dispatch_kq_unote_set_kevent(dispatch_unote_t _du, dispatch_kevent_t dk, | |
du->du_priority), | ||
#endif | ||
}; | ||
(void)pp; // if DISPATCH_USE_KEVENT_QOS == 0 | ||
} | ||
|
||
DISPATCH_ALWAYS_INLINE | ||
|
@@ -985,6 +991,7 @@ _dispatch_sync_ipc_handoff_end(dispatch_wlh_t wlh, mach_port_t port) | |
} | ||
#endif | ||
|
||
#if DISPATCH_HAVE_DIRECT_KNOTES | ||
DISPATCH_NOINLINE | ||
static bool | ||
_dispatch_kq_unote_update(dispatch_wlh_t wlh, dispatch_unote_t _du, | ||
|
@@ -1055,6 +1062,7 @@ _dispatch_kq_unote_update(dispatch_wlh_t wlh, dispatch_unote_t _du, | |
dispatch_assume_zero(r); | ||
return true; | ||
} | ||
#endif // DISPATCH_HAVE_DIRECT_KNOTES | ||
|
||
#pragma mark dispatch_muxnote_t | ||
|
||
|
@@ -1300,6 +1308,7 @@ enum { | |
DISPATCH_WORKLOOP_SYNC_END, | ||
}; | ||
|
||
#if DISPATCH_USE_KEVENT_WORKLOOP | ||
static char const * const _dispatch_workloop_actions[] = { | ||
[DISPATCH_WORKLOOP_ASYNC] = "async", | ||
[DISPATCH_WORKLOOP_ASYNC_FROM_SYNC] = "async (from sync)", | ||
|
@@ -1316,6 +1325,7 @@ static char const * const _dispatch_workloop_actions[] = { | |
[DISPATCH_WORKLOOP_SYNC_WAKE] = "sync-wake", | ||
[DISPATCH_WORKLOOP_SYNC_END] = "sync-end", | ||
}; | ||
#endif // DISPATCH_USE_KEVENT_WORKLOOP | ||
|
||
void | ||
_dispatch_event_loop_atfork_child(void) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1048,7 +1048,7 @@ _dispatch_bug_kevent_vanished(dispatch_unote_t du) | |
"{ %p[%s], ident: %" PRIdPTR " / 0x%" PRIxPTR ", handler: %p }", | ||
dux_type(du._du)->dst_kind, dou._dq, | ||
dou._dq->dq_label ? dou._dq->dq_label : "<unknown>", | ||
du._du->du_ident, du._du->du_ident, func); | ||
(intptr_t)du._du->du_ident, (intptr_t)du._du->du_ident, func); | ||
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. If we're going to cast here, we might as well choose |
||
} | ||
|
||
#endif // RDAR_49023449 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ | |
#define __DISPATCH_BUILDING_DISPATCH__ | ||
#define __DISPATCH_INDIRECT__ | ||
|
||
#ifdef __APPLE__ | ||
#ifdef __APPLE__DISPATCH_USE_KEVENT_WORKLOOP | ||
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.
|
||
#include <Availability.h> | ||
#include <os/availability.h> | ||
#include <TargetConditionals.h> | ||
|
@@ -277,6 +277,9 @@ upcast(dispatch_object_t dou) | |
#include <sys/sysctl.h> | ||
#include <sys/queue.h> | ||
#endif | ||
#if defined(__FreeBSD__) | ||
#include <sys/eventfd.h> | ||
#endif // __FreeBSD__ | ||
#include <sys/socket.h> | ||
#include <sys/time.h> | ||
#include <sys/mman.h> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,21 @@ _dispatch_thread_switch(dispatch_lock value, dispatch_lock_options_t flags, | |
#endif | ||
#endif | ||
|
||
#if defined(__FreeBSD__) | ||
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 could be merged above and the |
||
#if !HAVE_UL_UNFAIR_LOCK | ||
DISPATCH_ALWAYS_INLINE | ||
static inline void | ||
_dispatch_thread_switch(dispatch_lock value, dispatch_lock_options_t flags, | ||
uint32_t timeout) | ||
{ | ||
(void)value; | ||
(void)flags; | ||
(void)timeout; | ||
sched_yield(); | ||
} | ||
#endif | ||
#endif | ||
|
||
#pragma mark - semaphores | ||
|
||
#if USE_MACH_SEM | ||
|
@@ -509,6 +524,16 @@ _dispatch_wait_on_address(uint32_t volatile *_address, uint32_t value, | |
return _dispatch_futex_wait(address, value, NULL, FUTEX_PRIVATE_FLAG); | ||
#elif defined(_WIN32) | ||
return WaitOnAddress(address, &value, sizeof(value), INFINITE) == TRUE; | ||
#elif defined(__FreeBSD__) | ||
(void)flags; | ||
if (nsecs != DISPATCH_TIME_FOREVER) { | ||
struct timespec ts = { | ||
.tv_sec = (__typeof__(ts.tv_sec))(nsecs / NSEC_PER_SEC), | ||
.tv_nsec = (__typeof__(ts.tv_nsec))(nsecs % NSEC_PER_SEC), | ||
}; | ||
return _umtx_op((void*)address, UMTX_OP_WAIT_UINT, value, (void*)(uintptr_t)sizeof(struct timespec), (void*)&ts); | ||
} | ||
return _umtx_op((void*)address, UMTX_OP_WAIT_UINT, value, 0, 0); | ||
#else | ||
#error _dispatch_wait_on_address unimplemented for this platform | ||
#endif | ||
|
@@ -523,6 +548,8 @@ _dispatch_wake_by_address(uint32_t volatile *address) | |
_dispatch_futex_wake((uint32_t *)address, INT_MAX, FUTEX_PRIVATE_FLAG); | ||
#elif defined(_WIN32) | ||
WakeByAddressAll((uint32_t *)address); | ||
#elif defined(__FreeBSD__) | ||
_umtx_op((void*)address, UMTX_OP_WAKE, INT_MAX, 0, 0); | ||
#else | ||
(void)address; | ||
#endif | ||
|
@@ -682,7 +709,7 @@ _dispatch_once_wait(dispatch_once_gate_t dgo) | |
_dispatch_futex_wait(lock, (dispatch_lock)new_v, NULL, | ||
FUTEX_PRIVATE_FLAG); | ||
#else | ||
_dispatch_thread_switch(new_v, 0, timeout++); | ||
_dispatch_thread_switch((dispatch_lock)new_v, 0, timeout++); | ||
#endif | ||
(void)timeout; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,7 +174,7 @@ extension DispatchSource { | |
} | ||
#endif | ||
|
||
#if !os(Linux) && !os(Android) && !os(Windows) | ||
#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD) | ||
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. ...and then we're going to have to eventually |
||
public class func makeProcessSource(identifier: pid_t, eventMask: ProcessEvent, queue: DispatchQueue? = nil) -> DispatchSourceProcess { | ||
let source = dispatch_source_create(_swift_dispatch_source_type_PROC(), UInt(identifier), eventMask.rawValue, queue?.__wrapped) | ||
return DispatchSource(source: source) as DispatchSourceProcess | ||
|
@@ -224,7 +224,7 @@ extension DispatchSource { | |
return DispatchSource(source: source) as DispatchSourceUserDataReplace | ||
} | ||
|
||
#if !os(Linux) && !os(Android) && !os(Windows) | ||
#if !os(Linux) && !os(Android) && !os(Windows) && !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 | ||
|
@@ -290,7 +290,7 @@ extension DispatchSourceMemoryPressure { | |
} | ||
#endif | ||
|
||
#if !os(Linux) && !os(Android) && !os(Windows) | ||
#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD) | ||
extension DispatchSourceProcess { | ||
public var handle: pid_t { | ||
return pid_t(dispatch_source_get_handle(self as! DispatchSource)) | ||
|
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.
We have
DISPATCH_USE_KEVENT_QOS
insrc/event/event_config.h
that might be more declarative here.