Page MenuHomeFreeBSD

D3390.diff
No OneTemporary

D3390.diff

Index: share/man/man9/kproc.9
===================================================================
--- share/man/man9/kproc.9
+++ share/man/man9/kproc.9
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd October 19, 2007
+.Dd August 15, 2015
.Dt KPROC 9
.Os
.Sh NAME
@@ -179,11 +179,14 @@
The
.Fa ecode
argument specifies the exit status of the process.
-While exiting, the function
-.Xr exit1 9
-will initiate a call to
-.Xr wakeup 9
-on the process handle.
+A
+.Fn wakeup
+is issued on the proc pointer which can be used by callers to know
+when the called function is no longer running.
+See the
+.Sx EXAMPLES
+section for how to use this to ensure that a module
+is unloaded safely.
.Pp
The
.Fn kproc_resume ,
@@ -321,6 +324,40 @@
}
}
.Ed
+.Pp
+When the process is started as part of a module, the module must ensure
+that the module's code is no longer executing.
+.Bd -literal -offset indent
+struct mtx proc_interlock;
+volatile int proc_intervar;
+struct proc *procptr; /* prointer from kproc_create */
+
+void
+kproc_fun(void *arg)
+{
+
+ for (;;) {
+ mtx_lock(&proc_interlock);
+ if (proc_intervar)
+ break;
+ mtx_unlock(&proc_interlock);
+
+ /* do work */
+ }
+
+ kproc_exit(0);
+}
+
+void
+unloadmod(void)
+{
+
+ mtx_lock(&proc_interlock);
+ proc_intervar = 1;
+ mtx_sleep(procptr, &proc_interlock, PDROP, "procexit", 0);
+ /* kproc_fun has returned, and module is safe to unload. */
+}
+.Ed
.Sh ERRORS
The
.Fn kproc_resume
Index: share/man/man9/kthread.9
===================================================================
--- share/man/man9/kthread.9
+++ share/man/man9/kthread.9
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 15, 2014
+.Dd August 15, 2015
.Dt KTHREAD 9
.Os
.Sh NAME
@@ -195,9 +195,17 @@
The
.Fn kthread_exit
function is used to terminate kernel threads.
-It should be called by the main function of the kernel thread rather than
+It must be called by the main function of the kernel thread rather than
letting the main function return to its caller.
-.\" XXX "int ecode" argument isn't documented.
+A
+.Fn wakeup
+is issued on the thread pointer which can be used to know when the called
+function is no longer running.
+See the EXAMPLES section in
+.Xr kproc 9
+for how to use this to ensure that a module is unloaded safely.
+The example uses struct proc instead of struct thread, but otherwise is
+the same.
.Pp
The
.Fn kthread_resume ,

File Metadata

Mime Type
text/plain
Expires
Mon, Mar 23, 4:57 AM (15 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30158752
Default Alt Text
D3390.diff (2 KB)

Event Timeline