proc_compare(): weed out zombies before doing anything else. From skrll@.

This commit is contained in:
ad 2020-01-06 11:16:35 +00:00
parent 88d36e0e09
commit 6ee4781f70
1 changed files with 14 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: proc_compare.c,v 1.1 2011/10/21 02:09:00 christos Exp $ */
/* $NetBSD: proc_compare.c,v 1.2 2020/01/06 11:16:35 ad Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -37,7 +37,7 @@
# include <sys/cdefs.h>
# if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: proc_compare.c,v 1.1 2011/10/21 02:09:00 christos Exp $");
__RCSID("$NetBSD: proc_compare.c,v 1.2 2020/01/06 11:16:35 ad Exp $");
# endif
# include <sys/types.h>
@ -52,7 +52,7 @@ __RCSID("$NetBSD: proc_compare.c,v 1.1 2011/10/21 02:09:00 christos Exp $");
# define P_RTIME_USEC p_rtime_usec
# else
# include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: proc_compare.c,v 1.1 2011/10/21 02:09:00 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: proc_compare.c,v 1.2 2020/01/06 11:16:35 ad Exp $");
# include <sys/param.h>
# include <sys/inttypes.h>
# include <sys/systm.h>
@ -88,6 +88,17 @@ __KERNEL_RCSID(0, "$NetBSD: proc_compare.c,v 1.1 2011/10/21 02:09:00 christos Ex
int
proc_compare(const PROC *p1, const LWP *l1, const PROC *p2, const LWP *l2)
{
/*
* weed out zombies
*/
switch (TESTAB(P_ZOMBIE(p1), P_ZOMBIE(p2))) {
case ONLYA:
return 1;
case ONLYB:
return 0;
case BOTH:
goto out;
}
/*
* see if at least one of them is runnable
*/
@ -104,17 +115,6 @@ proc_compare(const PROC *p1, const LWP *l1, const PROC *p2, const LWP *l2)
return 1;
goto out;
}
/*
* weed out zombies
*/
switch (TESTAB(P_ZOMBIE(p1), P_ZOMBIE(p2))) {
case ONLYA:
return 1;
case ONLYB:
return 0;
case BOTH:
goto out;
}
/*
* pick the one with the smallest sleep time
*/