Skip to content

Commit c4d78d3

Browse files
committed
Light cleanup of the kevent backend.
Some functionality requires particular preprocessor feature flags to be set but errors are raised if they aren't, so the remedy is to put these behind relevant feature flags. * dispatch_kevent_t has a qos field only when DISPATCH_USE_KEVENT_QOS * _dispatch_kq_unote_update requires DISPATCH_HAVE_DIRECT_KNOTES as it is only called from functions behind this * _dispatch_workloop_actions and the associated enum are only used when DISPATCH_USE_KEVENT_WORKLOOP. Some unused variable void casts are removed (guard_ptr and pp), which do not refer to variables -- these may be upstream merge artefacts. A type cast is made to match types for _dispatch_bug_kevent_client. This function is incorrectly placed behind HAVE_MACH in src/init.c, but to keep the scope and impact of this commit narrow, we will defer that change. Since EVFILT_FS is not supported on all kevent implementations, put these behind an #ifdef. EVFILT_USER also requires similar handling, but since EVFILT_USER kevents are used intrinsically as part of the functionality, these will be handled in a separate commit.
1 parent f13ea5d commit c4d78d3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Diff for: src/event/event_kevent.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ _evfiltstr(short filt)
101101
_evfilt2(EVFILT_MACHPORT);
102102
_evfilt2(DISPATCH_EVFILT_MACH_NOTIFICATION);
103103
#endif
104+
#ifdef EVFILT_FS
104105
_evfilt2(EVFILT_FS);
106+
#endif
105107
_evfilt2(EVFILT_USER);
106108
#ifdef EVFILT_SOCK
107109
_evfilt2(EVFILT_SOCK);
@@ -388,16 +390,18 @@ _dispatch_kevent_print_error(dispatch_kevent_t ke)
388390
switch (ke->data) {
389391
case 0:
390392
return;
393+
#if DISPATCH_USE_KEVENT_QOS
391394
case ERANGE: /* A broken QoS was passed to kevent_id() */
392395
DISPATCH_INTERNAL_CRASH(ke->qos, "Invalid kevent priority");
396+
#endif
393397
default:
394398
// log the unexpected error
395399
_dispatch_bug_kevent_client("kevent", _evfiltstr(ke->filter),
396400
!ke->udata ? NULL :
397401
ke->flags & EV_DELETE ? "delete" :
398402
ke->flags & EV_ADD ? "add" :
399403
ke->flags & EV_ENABLE ? "enable" : "monitor",
400-
(int)ke->data, ke->ident, ke->udata, du);
404+
(int)ke->data, ke->ident, (uint64_t)ke->udata, du);
401405
}
402406
}
403407

@@ -591,7 +595,6 @@ _dispatch_kq_create(intptr_t *fd_ptr)
591595
guardid_t guard = (uintptr_t)fd_ptr;
592596
kqfd = guarded_kqueue_np(&guard, GUARD_CLOSE | GUARD_DUP);
593597
#else
594-
(void)guard_ptr;
595598
kqfd = kqueue();
596599
#endif
597600
if (kqfd == -1) {
@@ -860,7 +863,6 @@ _dispatch_kq_unote_set_kevent(dispatch_unote_t _du, dispatch_kevent_t dk,
860863
du->du_priority),
861864
#endif
862865
};
863-
(void)pp; // if DISPATCH_USE_KEVENT_QOS == 0
864866
}
865867

866868
DISPATCH_ALWAYS_INLINE
@@ -985,6 +987,7 @@ _dispatch_sync_ipc_handoff_end(dispatch_wlh_t wlh, mach_port_t port)
985987
}
986988
#endif
987989

990+
#if DISPATCH_HAVE_DIRECT_KNOTES
988991
DISPATCH_NOINLINE
989992
static bool
990993
_dispatch_kq_unote_update(dispatch_wlh_t wlh, dispatch_unote_t _du,
@@ -1055,6 +1058,7 @@ _dispatch_kq_unote_update(dispatch_wlh_t wlh, dispatch_unote_t _du,
10551058
dispatch_assume_zero(r);
10561059
return true;
10571060
}
1061+
#endif
10581062

10591063
#pragma mark dispatch_muxnote_t
10601064

@@ -1283,6 +1287,7 @@ _dispatch_unote_unregister_direct(dispatch_unote_t du, uint32_t flags)
12831287
#pragma mark -
12841288
#pragma mark dispatch_event_loop
12851289

1290+
#if DISPATCH_USE_KEVENT_WORKLOOP
12861291
enum {
12871292
DISPATCH_WORKLOOP_ASYNC,
12881293
DISPATCH_WORKLOOP_ASYNC_FROM_SYNC,
@@ -1316,6 +1321,7 @@ static char const * const _dispatch_workloop_actions[] = {
13161321
[DISPATCH_WORKLOOP_SYNC_WAKE] = "sync-wake",
13171322
[DISPATCH_WORKLOOP_SYNC_END] = "sync-end",
13181323
};
1324+
#endif
13191325

13201326
void
13211327
_dispatch_event_loop_atfork_child(void)
@@ -2445,6 +2451,7 @@ const dispatch_source_type_s _dispatch_source_type_vnode = {
24452451
.dst_merge_evt = _dispatch_source_merge_evt,
24462452
};
24472453

2454+
#ifdef EVFILT_FS
24482455
const dispatch_source_type_s _dispatch_source_type_vfs = {
24492456
.dst_kind = "vfs",
24502457
.dst_filter = EVFILT_FS,
@@ -2477,6 +2484,7 @@ const dispatch_source_type_s _dispatch_source_type_vfs = {
24772484
.dst_create = _dispatch_unote_create_without_handle,
24782485
.dst_merge_evt = _dispatch_source_merge_evt,
24792486
};
2487+
#endif
24802488

24812489
#ifdef EVFILT_SOCK
24822490
const dispatch_source_type_s _dispatch_source_type_sock = {

0 commit comments

Comments
 (0)