/* The class is added to priority event queue to indicate that class will change its mode in cl->pq_key microseconds. Make sure that class is not already in the queue.  */
static void htb_add_to_wait_tree(struct htb_sched *q, struct htb_class *cl, long delay)
/* The class is added to priority event queue to indicate that class will change its mode in cl->pq_key microseconds. Make sure that class is not already in the queue.  */
static void htb_add_to_wait_tree(struct htb_sched *q, struct htb_class *cl, long delay)
{
	struct rb_node **p = &q->wait_pq[cl->level].rb_node, *parent = NULL;
	cl->pq_key = q->now + delay;
	if (cl->pq_key == q->now)
		cl->pq_key++;
	if (q->near_ev_cache[cl->level] > cl->pq_key)
		q->near_ev_cache[cl->level] = cl->pq_key;
	while (*p) {
		struct htb_class *c;
		parent = *p;
		c = rb_entry(parent, struct htb_class, pq_node);
		if (cl->pq_key >= c->pq_key)
			p = &parent->rb_right;
		else
			p = &parent->rb_left;
	}
	rb_link_node(&cl->pq_node, parent, p);
	rb_insert_color(&cl->pq_node, &q->wait_pq[cl->level]);
}