tech-kern archive

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

rfc: kthread_join(9)



I have written kthread_join(9).  It waits for a kernel thread to finish.
See attachment.  The idea is that when a device driver detaches from its
device, should indicate to its worker threads that they should stop, and
then wait for those threads to *actually* stop.  Comments?

(I haven't written the doco, yet, but I will before I commit.)

Dave

-- 
David Young             OJC Technologies
dyoung%ojctech.com@localhost      Urbana, IL * (217) 278-3933
Index: sys/kern/kern_kthread.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_kthread.c,v
retrieving revision 1.26
diff -p -u -u -p -r1.26 kern_kthread.c
--- sys/kern/kern_kthread.c     30 Jan 2009 04:09:35 -0000      1.26
+++ sys/kern/kern_kthread.c     7 Apr 2009 21:40:23 -0000
@@ -148,6 +148,18 @@ kthread_create(pri_t pri, int flag, stru
        return (0);
 }
 
+int
+kthread_join(lwp_t *l)
+{
+       int error;
+
+       mutex_enter(proc0.p_lock);
+       error = lwp_wait1(curlwp, l->l_lid, NULL, 0);
+       mutex_exit(proc0.p_lock);
+
+       return error;
+}
+
 /*
  * Cause a kernel thread to exit.  Assumes the exiting thread is the
  * current context.
Index: sys/sys/kthread.h
===================================================================
RCS file: /cvsroot/src/sys/sys/kthread.h,v
retrieving revision 1.8
diff -p -u -u -p -r1.8 kthread.h
--- sys/sys/kthread.h   29 Jan 2009 22:00:26 -0000      1.8
+++ sys/sys/kthread.h   7 Apr 2009 21:40:27 -0000
@@ -51,6 +51,7 @@ int   kthread_create(pri_t, int, struct cp
            __attribute__((__format__(__printf__,7,8)));
 void   kthread_exit(int) __dead;
 void   kthread_destroy(lwp_t *);
+int    kthread_join(lwp_t *);
 #endif /* _KERNEL */
 
 #endif /* _SYS_KTHREAD_H_ */


Home | Main Index | Thread Index | Old Index