diff options
author | Visa Hankala <visa@cvs.openbsd.org> | 2022-02-13 13:03:03 +0000 |
---|---|---|
committer | Visa Hankala <visa@cvs.openbsd.org> | 2022-02-13 13:03:03 +0000 |
commit | 5f4d7e6fca2e67241a15bd6dbea6069c412e228e (patch) | |
tree | 92028944703856205b4480f9aa3ca7c28cf98416 /sys | |
parent | a5ad6533c0850395ad554e2b4adc31108a1ab38a (diff) |
Add helper functions for f_modify and f_process to condense code
These new functions, knote_modify() and knote_process(), implement
the logic that is common to most f_modify and f_process instances.
The code is inlined so as to not add yet another call frame on the
already towering stack of kqueue functions. Also, the _fn versions
allow direct calling of an event function when there is only one
filter type to handle.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/sys/event.h | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/sys/sys/event.h b/sys/sys/event.h index 2ec51183892..6aa346183cb 100644 --- a/sys/sys/event.h +++ b/sys/sys/event.h @@ -1,4 +1,4 @@ -/* $OpenBSD: event.h,v 1.65 2022/02/13 12:58:46 visa Exp $ */ +/* $OpenBSD: event.h,v 1.66 2022/02/13 13:03:02 visa Exp $ */ /*- * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org> @@ -317,6 +317,45 @@ extern void klist_remove_locked(struct klist *, struct knote *); extern void klist_invalidate(struct klist *); static inline int +knote_modify_fn(const struct kevent *kev, struct knote *kn, + int (*f_event)(struct knote *, long)) +{ + knote_assign(kev, kn); + return ((*f_event)(kn, 0)); +} + +static inline int +knote_modify(const struct kevent *kev, struct knote *kn) +{ + return (knote_modify_fn(kev, kn, kn->kn_fop->f_event)); +} + +static inline int +knote_process_fn(struct knote *kn, struct kevent *kev, + int (*f_event)(struct knote *, long)) +{ + int active; + + /* + * If called from kqueue_scan(), skip f_event + * when EV_ONESHOT is set, to preserve old behaviour. + */ + if (kev != NULL && (kn->kn_flags & EV_ONESHOT)) + active = 1; + else + active = (*f_event)(kn, 0); + if (active) + knote_submit(kn, kev); + return (active); +} + +static inline int +knote_process(struct knote *kn, struct kevent *kev) +{ + return (knote_process_fn(kn, kev, kn->kn_fop->f_event)); +} + +static inline int klist_empty(struct klist *klist) { return (SLIST_EMPTY(&klist->kl_list)); |