From d4345d7eb14a96c4cf845db398ad0e8ad8752875 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 2 Aug 2001 03:47:18 +0000 Subject: 2001-08-01 Roland McGrath * mgt.c (genpid): Rewritten. --- proc/mgt.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'proc') diff --git a/proc/mgt.c b/proc/mgt.c index 1291a80b..3daf7dac 100644 --- a/proc/mgt.c +++ b/proc/mgt.c @@ -677,7 +677,7 @@ static struct proc * new_proc (task_t task) { struct proc *p; - + p = allocate_proc (task); if (p) complete_proc (p, genpid ()); @@ -846,30 +846,16 @@ genpid () static int nextpid = 0; static int wrap = WRAP_AROUND; - int wrapped = 0; - - if (nextpid > wrap) + while (nextpid < wrap && !pidfree (nextpid)) + ++nextpid; + if (nextpid >= wrap) { nextpid = START_OVER; - wrapped = 1; - } + while (!pidfree (nextpid)) + nextpid++; - while (!pidfree (nextpid)) - { - ++nextpid; - if (nextpid > wrap) - { - if (wrapped) - { - wrap *= 2; - wrapped = 0; - } - else - { - nextpid = START_OVER; - wrapped = 1; - } - } + while (nextpid > wrap) + wrap *= 2; } return nextpid++; -- cgit v1.2.3