summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2020-12-09 18:58:20 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2020-12-09 18:58:20 +0000
commitd748bb807f88a010d30ec3116ae990da076dc35c (patch)
tree8a165a7da5d9403305c30b55ba930f0550786ef3 /sys/kern
parent61b1904725cad42591c2ade2185c747b6b6d5471 (diff)
Add kernel-only per-thread kqueue & helpers to initialize and free it.
This will soon be used by select(2) and poll(2). ok anton@, visa@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_event.c36
-rw-r--r--sys/kern/kern_exit.c4
2 files changed, 37 insertions, 3 deletions
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index d945c0692d3..9cd7c7dac8f 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_event.c,v 1.146 2020/12/07 11:15:50 mpi Exp $ */
+/* $OpenBSD: kern_event.c,v 1.147 2020/12/09 18:58:19 mpi Exp $ */
/*-
* Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
@@ -57,6 +57,7 @@
#include <sys/timeout.h>
#include <sys/wait.h>
+struct kqueue *kqueue_alloc(struct filedesc *);
void kqueue_terminate(struct proc *p, struct kqueue *);
void kqueue_free(struct kqueue *);
void kqueue_init(void);
@@ -504,6 +505,31 @@ const struct filterops dead_filtops = {
.f_event = filt_dead,
};
+void
+kqpoll_init(void)
+{
+ struct proc *p = curproc;
+
+ if (p->p_kq != NULL)
+ return;
+
+ p->p_kq = kqueue_alloc(p->p_fd);
+ p->p_kq_serial = arc4random();
+}
+
+void
+kqpoll_exit(void)
+{
+ struct proc *p = curproc;
+
+ if (p->p_kq == NULL)
+ return;
+
+ kqueue_terminate(p, p->p_kq);
+ kqueue_free(p->p_kq);
+ p->p_kq = NULL;
+}
+
struct kqueue *
kqueue_alloc(struct filedesc *fdp)
{
@@ -1144,7 +1170,7 @@ kqueue_stat(struct file *fp, struct stat *st, struct proc *p)
}
void
-kqueue_terminate(struct proc *p, struct kqueue *kq)
+kqueue_purge(struct proc *p, struct kqueue *kq)
{
int i;
@@ -1156,6 +1182,12 @@ kqueue_terminate(struct proc *p, struct kqueue *kq)
for (i = 0; i < kq->kq_knhashmask + 1; i++)
knote_remove(p, &kq->kq_knhash[i]);
}
+}
+
+void
+kqueue_terminate(struct proc *p, struct kqueue *kq)
+{
+ kqueue_purge(p, kq);
kq->kq_state |= KQ_DYING;
kqueue_wakeup(kq);
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 92bbfe915b5..4738000e10d 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_exit.c,v 1.192 2020/12/07 16:55:28 mpi Exp $ */
+/* $OpenBSD: kern_exit.c,v 1.193 2020/12/09 18:58:19 mpi Exp $ */
/* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */
/*
@@ -185,6 +185,8 @@ exit1(struct proc *p, int xexit, int xsig, int flags)
if ((p->p_flag & P_THREAD) == 0)
pr->ps_siglist = 0;
+ kqpoll_exit();
+
#if NKCOV > 0
kcov_exit(p);
#endif