Commit 13a0efaf authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Pavel Emelyanov

pstree: Simplify get_free_pid()

The expression rb_entry(node, struct pstree_item, pid.node)
may create a fake impression, that we dereferrence pstree_item
for threads too, which is a BUG, but it's not so, because
we are only interested in its ->pid field.

But anyway, escape of pstree_item, iterate over struct pid,
which are more readable.

travis-ci: success for Make pstree_item::pid allocated dynamically
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent d3ea14a1
......@@ -583,23 +583,23 @@ err:
#define RESERVED_PIDS 300
static int get_free_pid()
{
static struct pstree_item *prev, *next;
static struct pid *prev, *next;
if (prev == NULL)
prev = rb_entry(rb_first(&pid_root_rb), struct pstree_item, pid.node);
prev = rb_entry(rb_first(&pid_root_rb), struct pid, node);
while (1) {
struct rb_node *node;
pid_t pid;
pid = prev->pid.virt + 1;
pid = prev->virt + 1;
pid = pid < RESERVED_PIDS ? RESERVED_PIDS + 1 : pid;
node = rb_next(&prev->pid.node);
node = rb_next(&prev->node);
if (node == NULL)
return pid;
next = rb_entry(node, struct pstree_item, pid.node);
if (next->pid.virt > pid)
next = rb_entry(node, struct pid, node);
if (next->virt > pid)
return pid;
prev = next;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment