Testing whether a process is (currently) done by checking whether the 
process's thread list has a single item.  This is currently done in just 
two places, but I expect to need this in more places, so let's abstract 
that into an inline function.

Philip Guenther


Index: sys/proc.h
===================================================================
RCS file: /cvs/src/sys/sys/proc.h,v
retrieving revision 1.172
diff -u -p -r1.172 proc.h
--- sys/proc.h  25 Oct 2013 04:42:48 -0000      1.172
+++ sys/proc.h  14 Dec 2013 03:33:43 -0000
@@ -523,6 +523,13 @@ int        single_thread_set(struct proc *, enu
 void   single_thread_clear(struct proc *, int);
 int    single_thread_check(struct proc *, int);
 
+static __inline int
+process_is_multithreaded(struct process *pr)
+{
+       struct proc *p = TAILQ_FIRST(&pr->ps_threads);
+       return (p != NULL && TAILQ_NEXT(p, p_thr_link) != NULL);
+}
+
 void   child_return(void *);
 
 int    proc_cansugid(struct proc *);
Index: kern/kern_exit.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_exit.c,v
retrieving revision 1.129
diff -u -p -r1.129 kern_exit.c
--- kern/kern_exit.c    25 Oct 2013 04:42:48 -0000      1.129
+++ kern/kern_exit.c    14 Dec 2013 03:33:43 -0000
@@ -127,8 +127,7 @@ exit1(struct proc *p, int rv, int flags)
        pr = p->p_p;
 
        /* single-threaded? */
-       if (TAILQ_FIRST(&pr->ps_threads) == p &&
-           TAILQ_NEXT(p, p_thr_link) == NULL) {
+       if (!process_is_multithreaded(pr)) {
                flags = EXIT_NORMAL;
        } else {
                /* nope, multi-threaded */
Index: kern/kern_sig.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_sig.c,v
retrieving revision 1.155
diff -u -p -r1.155 kern_sig.c
--- kern/kern_sig.c     8 Oct 2013 03:50:07 -0000       1.155
+++ kern/kern_sig.c     14 Dec 2013 03:33:43 -0000
@@ -1388,8 +1388,7 @@ sigexit(struct proc *p, int signum)
                p->p_sisig = signum;
 
                /* if there are other threads, pause them */
-               if (TAILQ_FIRST(&p->p_p->ps_threads) != p ||
-                   TAILQ_NEXT(p, p_thr_link) != NULL)
+               if (process_is_multithreaded(p->p_p))
                        single_thread_set(p, SINGLE_SUSPEND, 0);
 
                if (coredump(p) == 0)

Reply via email to