/* Remove the highest priority context on the runqueue and return it to the caller. Returns NULL if no runnable context was found.  */
static struct spu_context* grab_runnable_context(int prio, int node)
/* Remove the highest priority context on the runqueue and return it to the caller. Returns NULL if no runnable context was found.  */
static struct spu_context* grab_runnable_context(int prio, int node)
{
	struct spu_context *ctx;
	int best;
	spin_lock(&spu_prio->runq_lock);
	best = find_first_bit(spu_prio->bitmap, prio);
	while (best < prio) {
		struct list_head *rq = &spu_prio->runq[best];
		list_for_each_entry(ctx, rq, rq) {
			if (__node_allowed(ctx, node)) {
				__spu_del_from_rq(ctx);
				goto found;
			}
		}
		best++;
	}
	ctx = NULL;
 found:
	spin_unlock(&spu_prio->runq_lock);
	return ctx;
}