Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Make some knote implementation details private to kern_e...



details:   https://anonhg.NetBSD.org/src/rev/2a4ccc8dd8ee
branches:  trunk
changeset: 368555:2a4ccc8dd8ee
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue Jul 19 00:46:00 2022 +0000

description:
Make some knote implementation details private to kern_event.c.  NFC, and
no ABI change for kevent providers.

diffstat:

 sys/kern/kern_event.c |  77 +++++++++++++++++++++++++++++++++-----------------
 sys/sys/event.h       |   3 +-
 2 files changed, 51 insertions(+), 29 deletions(-)

diffs (169 lines):

diff -r 2945de40055d -r 2a4ccc8dd8ee sys/kern/kern_event.c
--- a/sys/kern/kern_event.c     Mon Jul 18 23:34:02 2022 +0000
+++ b/sys/kern/kern_event.c     Tue Jul 19 00:46:00 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_event.c,v 1.143 2022/07/13 14:11:46 thorpej Exp $ */
+/*     $NetBSD: kern_event.c,v 1.144 2022/07/19 00:46:00 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2008, 2009, 2021 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 #endif /* _KERNEL_OPT */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.143 2022/07/13 14:11:46 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.144 2022/07/19 00:46:00 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -120,6 +120,40 @@
 static int     filt_user(struct knote *, long hint);
 static int     filt_usertouch(struct knote *, struct kevent *, long type);
 
+/*
+ * Private knote state that should never be exposed outside
+ * of kern_event.c
+ *
+ * Field locking:
+ *
+ * q   kn_kq->kq_lock
+ */
+struct knote_impl {
+       struct knote    ki_knote;
+       unsigned int    ki_influx;      /* q: in-flux counter */
+};
+
+#define        KIMPL_TO_KNOTE(kip)     (&(kip)->ki_knote)
+#define        KNOTE_TO_KIMPL(knp)     container_of((knp), struct knote_impl, ki_knote)
+
+static inline struct knote *
+knote_alloc(bool sleepok)
+{
+       struct knote_impl *ki;
+
+       ki = kmem_zalloc(sizeof(*ki), sleepok ? KM_SLEEP : KM_NOSLEEP);
+
+       return KIMPL_TO_KNOTE(ki);
+}
+
+static inline void
+knote_free(struct knote *kn)
+{
+       struct knote_impl *ki = KNOTE_TO_KIMPL(kn);
+
+       kmem_free(ki, sizeof(*ki));
+}
+
 static const struct fileops kqueueops = {
        .fo_name = "kqueue",
        .fo_read = (void *)enxio,
@@ -286,7 +320,7 @@
 kn_in_flux(struct knote *kn)
 {
        KASSERT(mutex_owned(&kn->kn_kq->kq_lock));
-       return kn->kn_influx != 0;
+       return KNOTE_TO_KIMPL(kn)->ki_influx != 0;
 }
 
 static inline bool
@@ -298,8 +332,9 @@
                return false;
        }
 
-       KASSERT(kn->kn_influx < UINT_MAX);
-       kn->kn_influx++;
+       struct knote_impl *ki = KNOTE_TO_KIMPL(kn);
+       KASSERT(ki->ki_influx < UINT_MAX);
+       ki->ki_influx++;
 
        return true;
 }
@@ -308,14 +343,17 @@
 kn_leave_flux(struct knote *kn)
 {
        KASSERT(mutex_owned(&kn->kn_kq->kq_lock));
-       KASSERT(kn->kn_influx > 0);
-       kn->kn_influx--;
-       return kn->kn_influx == 0;
+
+       struct knote_impl *ki = KNOTE_TO_KIMPL(kn);
+       KASSERT(ki->ki_influx > 0);
+       ki->ki_influx--;
+       return ki->ki_influx == 0;
 }
 
 static void
 kn_wait_flux(struct knote *kn, bool can_loop)
 {
+       struct knote_impl *ki = KNOTE_TO_KIMPL(kn);
        bool loop;
 
        KASSERT(mutex_owned(&kn->kn_kq->kq_lock));
@@ -325,7 +363,7 @@
         * dropping the kq_lock.  The caller has let us know in
         * 'can_loop'.
         */
-       for (loop = true; loop && kn->kn_influx != 0; loop = can_loop) {
+       for (loop = true; loop && ki->ki_influx != 0; loop = can_loop) {
                KQ_FLUX_WAIT(kn->kn_kq);
        }
 }
@@ -423,22 +461,6 @@
        return false;
 }
 
-static inline struct knote *
-knote_alloc(bool sleepok)
-{
-       struct knote *kn;
-
-       kn = kmem_zalloc(sizeof(*kn), sleepok ? KM_SLEEP : KM_NOSLEEP);
-
-       return kn;
-}
-
-static inline void
-knote_free(struct knote *kn)
-{
-       kmem_free(kn, sizeof(*kn));
-}
-
 static int
 filter_attach(struct knote *kn)
 {
@@ -2119,7 +2141,8 @@
        struct kqueue   *kq;
        struct kevent   *kevp;
        struct timespec ats, sleepts;
-       struct knote    *kn, *marker, morker;
+       struct knote    *kn, *marker;
+       struct knote_impl morker;
        size_t          count, nkev, nevents;
        int             timeout, error, touch, rv, influx;
        filedesc_t      *fdp;
@@ -2148,7 +2171,7 @@
        }
 
        memset(&morker, 0, sizeof(morker));
-       marker = &morker;
+       marker = &morker.ki_knote;
        marker->kn_kq = kq;
        marker->kn_status = KN_MARKER;
        mutex_spin_enter(&kq->kq_lock);
diff -r 2945de40055d -r 2a4ccc8dd8ee sys/sys/event.h
--- a/sys/sys/event.h   Mon Jul 18 23:34:02 2022 +0000
+++ b/sys/sys/event.h   Tue Jul 19 00:46:00 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: event.h,v 1.53 2022/07/13 14:11:46 thorpej Exp $       */
+/*     $NetBSD: event.h,v 1.54 2022/07/19 00:46:00 thorpej Exp $       */
 
 /*-
  * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon%FreeBSD.org@localhost>
@@ -262,7 +262,6 @@
        struct kfilter          *kn_kfilter;
        void                    *kn_hook;
        int                     kn_hookid;
-       unsigned int            kn_influx;      /* q: in-flux counter */
 
 #define        KN_ACTIVE       0x01U                   /* event has been triggered */
 #define        KN_QUEUED       0x02U                   /* event is on queue */



Home | Main Index | Thread Index | Old Index